5

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.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
  • Possible duplicate of [setNamedRange() outside of the spreadsheet container?](http://stackoverflow.com/questions/12323961/setnamedrange-outside-of-the-spreadsheet-container) – Rubén Nov 27 '16 at 15:51

2 Answers2

2

You may want to check out this post:

setNamedRange() outside of the spreadsheet container?

and see if that helps you ..

Community
  • 1
  • 1
JPV
  • 26,499
  • 4
  • 33
  • 48
1

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.

Juuso Nykänen
  • 369
  • 2
  • 12