Martin Feinstein
Martin Feinstein

Reputation: 83

"Currentregion" concept in Google Sheets script language

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?

Upvotes: 2

Views: 1062

Answers (3)

InExSu VBAGem t2d2
InExSu VBAGem t2d2

Reputation: 82

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.

Upvotes: 1

Jing Wang
Jing Wang

Reputation: 23

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.

Upvotes: 0

player0
player0

Reputation: 1

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

Upvotes: 1

Related Questions