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.
2 Answers
You may want to check out this post:
setNamedRange() outside of the spreadsheet container?
and see if that helps you ..
Comments
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.