Google-sheets – How to display the content of a (hidden) cell in a message box with a script

google sheetsgoogle-apps-script

I have created a button on my sheet and would like it to display the content of a hidden cell when click. I am now using the following script but it doesn't seem to be the right one as the wrong value is displayed. I want cell C2 to be displayed. Any suggestions?

function myFunction() {
 var ss = SpreadsheetApp.getActiveSpreadsheet();
 var sheet = ss.getSheetByName("Twee begrippen")  
 var range = sheet.getRange(2, 3, 1, 1);
 values = range.getValues();
  Browser.msgBox(values); 
}

The assumption on this answer is right in that the script is indeed referring to cell c2. However the information in the pop up is not correct. This has got to do with the way the information in cell C2 is generated. It is the product of a vlookup function. The value in cell B2 is looked up in a different sheet. Cell B2 however is generated by a random function. Now it appears that in some way the pop up produces an other lookup value than the one in cell C2.

Could you have a quick glance at the sheet and suggest how to overcome this hurdle? You can find the file here.

Best Answer

Besides some "style error" (missing var, ;) and the use of getValues() instead of getValue() the script looks to show the value of C2 from the Twee begrippen sheet. Perhaps you expect a value from another sheet, if so, you should replace Twee begrippen by the correct sheet name or use ss.getActiveSheet() to get the C2 value from the active sheet.