AllowEditRange and AllowEditRanges Members
Use the Protection object’s AllowEditRanges property to get a reference to the AllowEditRanges collection. The AllowEditRanges collection and AllowEditRange object provide the following members. Key members (shown in bold) are covered in the following reference section:
Use the AllowEditRanges collection to create ranges that allow edits by specific users. Excel prevents changes to ranges of cells that are protected and locked. The AllowEditRanges settings automatically unlock ranges of cells for the users included in the user-access list.
You must remove protection from a worksheet before you can add user-level permissions. For example, the following code unprotects a worksheet, creates a range that allows user-level permissions, and then restores protection:
Dim ws As Worksheet, ual As UserAccessList, aer As AllowEditRange, _
usr As UserAccess
Set ws = ThisWorkbook.Sheets("Protection")
ws.Unprotect "Excel2003"
Set aer = ws.Protection.AllowEditRanges.Add("Edit Range", ws.[a1:c4])
Set usr = aer.Users.Add("Power Users", True)
ws.Protect "Excel2003"Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access