"Currentregion" concept in Google Sheets script language

Viewed 563

From inside Google Sheets Script, I am trying to name a variable-sized matrix on the worksheet. In EXCEL VBA, I would go to the top left most cell and select the whole matrix using activecell.currentregion.select. This would select the whole matrix (e.g. D5:L50) on the worksheet, which I could then name.

Is there the same ability in Google Sheets script language. If not, can anyone figure out how to do this?

3 Answers
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('D5:L50').activate();

you can use macro under:

  • Tools > Macros > Record macro > and then make your selection > save macro > edit macro

SpreadsheetApp.Range

getDataRegion():

Returns a copy of the range expanded in the four cardinal Directions to cover all adjacent cells with data in them. If the range is surrounded by empty cells not including those along the diagonals, the range itself is returned. This is similar to selecting the range and typing Ctrl+A in the editor.

The question is: how do you refer to a range which contains values and most importantly, the range may change as user add or remove contents. In Excel VBA, this is dealt with a built-in function called "currentregion". I'm also curious if there is a equivalent in GS.

Related