Class NamedRange

NamedRange

Create, access and modify named ranges in a spreadsheet. Named ranges are ranges that have associated string aliases. They can be viewed and edited via the Sheets UI under the Data > Named ranges... menu.

Methods

MethodReturn typeBrief description
getName()StringGets the name of this named range.
getRange()RangeGets the range referenced by this named range.
remove()voidDeletes this named range.
setName(name)NamedRangeSets/updates the name of the named range.
setRange(range)NamedRangeSets/updates the range for this named range.

Detailed documentation

getName()

Gets the name of this named range.

Return

String — the name of this named range


getRange()

Gets the range referenced by this named range.

Return

Range — the spreadsheet range that is associated with this named range


remove()

Deletes this named range.


 // The code below will delete all the named ranges in the spreadsheet.
 var namedRanges = SpreadsheetApp.getActive().getNamedRanges();
 for (var i = 0; i < namedRanges.length; i++) {
   namedRanges[i].remove();
 }
 

setName(name)

Sets/updates the name of the named range.


 // The code below will update the name for the first named range.
 var namedRanges = SpreadsheetApp.getActiveSpreadsheet().getNamedRanges();
 if (namedRanges.length > 1) {
   namedRanges[0].setName("UpdatedNamedRange");
 }
 

Parameters

NameTypeDescription
nameStringthe new name of the named range

Return

NamedRange — the range whose name was set by the call


setRange(range)

Sets/updates the range for this named range.

Parameters

NameTypeDescription
rangeRangethe spreadsheet range to associate with this named range

Return

NamedRange — the named range for which the spreadsheet range was set

Send feedback about...

Apps Script
Apps Script