Delete ALL AllowEditRanges in command Button

Solved/Closed
Issa - Apr 14, 2011 at 12:49 PM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Jul 3, 2011 at 08:24 AM
Dear Sir,

I have the following VBA code:

Private Sub CommandButton2_Click()
Dim WS As Worksheet
Dim aer As AllowEditRange

For Each WS In Worksheets
For Each aer In ActiveSheet.Protection.AllowEditRanges
aer.Delete

Next aer
Next WS

End Sub

I need to modify this VBA in order to work for all worksheets, it works now only for the sheet that have the command button but the other sheets still having the AllowEditRange.

Therefore, some one if know what to add to this VBA or to change it in order when I click one command button to remove / delete all AllowEditRanges in all worksheets.

Thank you in advance

1 response

rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 766
Jul 3, 2011 at 08:24 AM
Change this line

ActiveSheet.Protection.AllowEditRanges

to

WS .Protection.AllowEditRanges
1