Macro- not re-password protecting

R

Roady

Hi:

I am using a macro that involves unprotecting and protecting the sheet at
the beginning and end of the macro. I have used this same code in a different
spreadsheet's macro and it worked fine (including the allow filter part).
However, when I run it on this spreadsheet, it re-protects it at the end, but
WITHOUT the password. the code I am using is as follows:

Sub Macro1()
ActiveSheet.Unprotect Password:="Stars"

(All Macro details go here...)

ActiveSheet.Protect Password:="Stars"
ActiveSheet.Protect AllowFiltering:=True

End Sub

Do you have any idea why it protects it but without the necessary password?
thank you!
 
G

Gord Dibben

The second Activesheet.Protect has no password so wipes out the first
Activesheet.Protect

Use this construct

With ActiveSheet
.Protect Password:="Stars"
.EnableAutoFilter = True
End With


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top