How to get the correct range to set the value to a cell?

user635600 picture user635600 · Jul 4, 2012 · Viewed 340.7k times · Source

I want to set text or number in Google Sheet from script.

I want to set Hello or number 9 in cell F2. I found this code so far:

SpreadsheetApp.getActiveRange().setValue('hello');

but that doesn't specify which cell.

Answer

megabyte1024 picture megabyte1024 · Jul 4, 2012

The following code does what is required

function doTest() {
  SpreadsheetApp.getActiveSheet().getRange('F2').setValue('Hello');
}