getrange js code example

Example 1: google sheets get ranges

//getRange(row, column, optNumRows, optNumColumns);
Sheet.getRange(1,1,1,12);

//row --- int --- top row of the range
//column --- int--- leftmost column of the range
//optNumRows --- int --- number of rows in the range.
//optNumColumns --- int --- number of columns in the range

Example 2: getRange

let SHEET = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  
let values = SHEET.getRange(2, 1, SHEET.getLastRow()-1, 1).getValues();
// .getRange(row, column, numRows, numColumns)
// So '.getLastRow()-1' because 'values' starts at the second row
  
let valuesDestination = SHEET.getRange(`B2:B${SHEET.getLastRow()}`)
  
valuesDestination.setValues(values);

Tags:

Go Example