Skip to main content

AddDefName

Adds a new name to the current worksheet.

Syntax

expression.AddDefName(sName, sRef, isHidden);

expression - A variable that represents a ApiWorksheet class.

Parameters

NameRequired/OptionalData typeDefaultDescription
sNameRequiredstringThe range name.
sRefRequiredstringMust 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 custom name to a cell range in a spreadsheet.

// How do I label a group of cells so I can refer to them by name in a spreadsheet?

// Give a range a memorable label instead of using raw cell addresses.

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