AllowEditRanges.Add method (Excel)

Adds a range that can be edited on a protected worksheet. Returns an AllowEditRange object.

Syntax

expression.Add (Title, Range, Password)

expression A variable that represents an AllowEditRanges object.

Parameters

Name Required/Optional Data type Description
Title Required String The title of the range.
Range Required Range Range object. The range allowed to be edited.
Password Optional Variant The password for the range.

Return value

An AllowEditRange object that represents the range.

Example

This example allows edits to range A1:A4 on the active worksheet, notifies the user, changes the password for this specified range, and then notifies the user of this change.

Sub UseChangePassword() 
 
 Dim wksOne As Worksheet 
 
 Set wksOne = Application.ActiveSheet 
 
 ' Protect the worksheet. 
 wksOne.Protect 
 
 ' Establish a range that can allow edits 
 ' on the protected worksheet. 
 wksOne.Protection.AllowEditRanges.Add _ 
 Title:="Classified", _ 
 Range:=Range("A1:A4"), _ 
 Password:="secret" 
 
 MsgBox "Cells A1 to A4 can be edited on the protected worksheet." 
 
 ' Change the password. 
 wksOne.Protection.AllowEditRanges(1).ChangePassword _ 
 Password:="moresecret" 
 
 MsgBox "The password for these cells has been changed." 
 
End Sub

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.