Guys,
I was hoping someone could me identify why this is happening. I have a macro code which sorts a defined set of rows based on a particular column. Likewise, there is a macro that unsorts them back to their original positions. Now the macros themselves work perfectly, however, the sheet needs to be protected before distribution. When I input the code to protect/unprotect the sheets before and after the macro has run, I get a subscript out of range error.
The name of the sheet in question is OER Dashboard Report and the password is Grimmer
Here is an example of one of the two macros that work perfectly:
Sub sortstores()
'Change first range as needed
'Do not change Key1
Range("C11:Y89").Sort Key1:=Range("F1"), _
Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers
End Sub
The subscript out of range error occurs when I change the code to this:
Sub sortstores()
Sheets("OER Dashboard Report").Unprotect Password:="Grimmer"
'Change first range as needed
'Do not change Key1
Range("C11:Y89").Sort Key1:=Range("F1"), _
Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers
Sheets("OER Dashboard Report").Protect Password:="Grimmer"
End Sub
Any ideas??
Bookmarks