PDA

View Full Version : Delete all AllowEditRanges in workbook



Learner123
12-08-2016, 12:50 PM
Hi All,

The below code keeps crashing on me and causes excel to disappear. I don't know why...

Can someone provide some insight??

My tabs are all protected and have password 123. I am trying to run through all the tabs and delete the Allow Users to Edit Ranges.


Sub UNpr()
Dim ws As Worksheet
Dim pwd As String
Dim aer As AllowEditRange
pwd = "123" ' Put your password here
For Each ws In Worksheets
ws.Unprotect Password:=pwd
For Each aer In ws.Protection.AllowEditRanges
aer.Delete
Next aer
Next ws
End Sub


Thanks

Learner123
12-08-2016, 01:30 PM
Figured it out - the below was missing from the code before the For Each aer line:


ws.Select