Skip to main content

AddDefName

Adds a new name to a range of cells.

Syntax

expression.AddDefName(sName, sRef, isHidden);

expression - A variable that represents a Api class.

Parameters

NameRequired/OptionalData typeDefaultDescription
sNameRequiredstringThe range name.
sRefRequiredstringThe reference to the specified range. It must contain the sheet name, followed by sign ! and a range of cells. Example: "Sheet1!$A$1:$B$2".
isHiddenRequiredbooleanDefines if the range name is hidden or not.

Returns

boolean

Example

Assign a named range to a group of cells for easier reference in a spreadsheet.

// How do I give a cell range a descriptive name in a spreadsheet?

// Label a range of cells so it can be referenced by name instead of address in a spreadsheet.

let worksheet = Api.GetActiveSheet();
worksheet.GetRange("A1").SetValue("1");
worksheet.GetRange("B1").SetValue("2");
Api.AddDefName("numbers", "Sheet1!$A$1:$B$1");
worksheet.GetRange("A3").SetValue("We defined a name 'numbers' for a range of cells A1:B1.");