Delete AllowEditeRanges by VBA [Solved/Closed]

Report
-
 Issa -
Dear All,

Can some-body help me to correct the following code:

Private Sub CommandButton1_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

This Code I do it to remove all AllowEditeRanges in every sheet, but unfortunately it works only in the sheet that the command button exists and NOT for every sheet.

So can anyone help me and thanks in advance.

1 reply

You have told it only to look at the ActiveSheet.

For Each aer In ActiveSheet.Protection.AllowEditRanges
Dear RayH,

First of al thanks to your reply, it didn't worked because I need it to work in EVERY worksheet in the workbook, not only in the active sheet, so I need it to work in every sheet.

Thank you in advance for your kind assistant.
Issa
It solved.Thanks a lot.