Skip to main content

AddProtectedRange

Creates a protected range of the specified type from the selected data range of the current sheet.

Syntax

expression.AddProtectedRange(sTitle, sDataRange);

expression - A variable that represents a ApiWorksheet class.

Parameters

NameRequired/OptionalData typeDefaultDescription
sTitleRequiredstringThe title which will be displayed for the current protected range.
sDataRangeRequiredstringThe selected cell range which will be used to get the data for the protected range.

Returns

ApiProtectedRange | null

Example

Lock a range of cells so it cannot be edited without permission in a spreadsheet.

// How do I protect a specific group of cells from changes in a spreadsheet?

// Restrict editing on a named cell range by marking it as protected.

let worksheet = Api.GetActiveSheet();
worksheet.GetRange("A1").SetValue("1");
worksheet.GetRange("B1").SetValue("2");
worksheet.AddProtectedRange("protectedRange", "Sheet1!$A$1:$B$1");