a module to work with named ranges in formulas
// add new range named "MYRANGE"
$$("ssheet").ranges.add("MYRANGE", "B2:C2", "Sheet 2");
Via this module you can add, name and manipulate cell ranges. For more information refer to the main article.
The ranges module has several methods to work with ranges:
Used to add new named range globally or to the active/specified sheet. The method takes the following parameters:
// add "MYRANGE" range to Sheet 1
$$("ssheet").ranges.add("MYRANGE", "B2:C2", "Sheet 1");
Optionally, you can state sheet name in the range.
// adds rangethat takes data from Sheet 1 to Sheet2
spreadsheet.ranges.add("MYRANGE", "Sheet1!A1:A3", "Sheet2");
Used to get the range of cells. The method takes the following parameters:
// "B2:C2"
$$("ssheet").ranges.getCode("MYRANGE", "Sheet 1");
Used to get all the existing named ranges. The method takes the only parameter:
// [{name:"K",range:"C3:D3", global: true},...]
$$("ssheet").ranges.getRanges("Sheet 1");
The flag global in the range object shows whether the range is visible globally.
Used to delete a specified named range. The method takes the following parameters:
To remove the range from the active sheet, do not pass the 2nd parameter.
// remove a global range named "globalRange"
$$("ssheet").ranges.remove("globalRange", true);
Used to remove all global or local named ranges. The method takes the only parameter:
// deletes all ranges from the Sheet 3
$$("sheet").ranges.clear("Sheet 3");
Used to parse new ranges. Comparing with the add() method, parse() is used to add more than 1 ranges. The method takes the following parameters:
// parse new ranges to Sheet 2
$$("sheet").ranges.parse([
["firstRange", "A1:A3"], //local range for Sheet 2
["secondRange", "B3:B7", true] //global range
], "Sheet 2");
Note that you can define ranges with sheet name ("Sheet1!C1:C5") or without ("C1:C5"). If range is defined without a sheet name it will take data from:
Used to get array(s) with range data of a specified sheet.
$$("sheet").ranges.serialize("Sheet 1");
/*
The method returns a 2D array like:
[
["firstRange", "A1:E3", false],
["secondRange", "B2:C2", false],
]
*/
The third element of the resulting array defines whether the range is visible globally.
Back to top