George Stevens
George Stevens

Reputation: 61

How to create a defined named range in google sheets using script

Is it possible to create named ranges in Google sheets using google script? I would then want the spreadsheet to be able to use these in formulas.

Upvotes: 6

Views: 8933

Answers (2)

Juuso Nykänen
Juuso Nykänen

Reputation: 448

Class SpreadSheet has the method setNamedRange(name, Range) that can be used.

var ss = SpreadsheetApp.getActiveSpreadsheet();
ss.setNamedRange("myNamedRange", SpreadsheetApp.getActiveRange());

Link to the Google Documentation: https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet?hl=en#setnamedrangename,-range

With me the pitfall was that I thought the method setNamedRange() belonged to the Class Range or Class Sheet. But turns out it belongs to the SpreadSheet Class.

Upvotes: 1

JPV
JPV

Reputation: 27292

You may want to check out this post:

setNamedRange() outside of the spreadsheet container?

and see if that helps you ..

Upvotes: 2

Related Questions