Get Range or Cell object by row and column number

Source code

function getRangeObject(){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getActiveSheet();
  var rng;

  // (2) Get by row and col number
  rng = sh.getRange(row, column);
  rng = sh.getRange(row, column, numRows);
  rng = sh.getRange(row, column, numRows, numColumns);
}

 

Format

(1) SheetObject.getRange(row, column) … One range object

(2) SheetObject.getRange(row, column, numRows) … Multiple ranges’ objects (1 column and multiple rows)

(3) SheetObject.getRange(row, column, numRows, numColumns) … Multiple ranges’ objects (multiple column and multiple rows)

 

Parameters

row … start row number to get

column … start column number to get

numRows … the number of rows you want to get

numColumns … the number of rows you want to get

 

Returns

Range objects

 

Sample code

function getRangeObject(){
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sh = ss.getActiveSheet();
  var rng;

  // Range A1
  rng = sh.getRange(1, 1);

  // Range A2:A4
  rng = sh.getRange(2, 1, 3);

  // Range A2:B4
  rng = sh.getRange(2, 1, 3, 2);
}

7 thoughts on “Get Range or Cell object by row and column number”

Leave a Comment