Get Range or Cell object by address

Source code

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

  // (3) Get by address
  rng = sh.getRange(a1Notation);
  rng = sh.getRangeList(a1Notations);
}

 

Format

(1) SheetObject.getRange(a1Notation) … Get one or sequential range object by addresses

(2) SheetObject.getRangeList(a1Notations) … Get multiple range object by addresses

 

Parameters

a1Notation … Cell address (ex. getRange(A1), getRange($A$1), getRange($A:$B), getRange($1:$2) …)

a1Notations … Cell address (ex. [‘A1:D4’, ‘F1:H4’])

 

Returns

Range object

 

Sample code

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

  // One address
  rng = sh.getRange("$A$1");

  // Sequential addresses
  rng = sh.getRange("$A:$B");
  rng = sh.getRange("$A$1:$B$3");
  rng = sh.getRange("$1:$2");

  // Multiple addresses
  rng = sh.getRangeList(['$A$1:$D$4', '$F$1:$H$4']);
}

4 thoughts on “Get Range or Cell object by address”

Leave a Comment