Unprotect Worksheet in VBA

Hello Experts,

I have this code on my workbook:

Sub EmployeesShowAndHideColumns()
Columns(EmpToggleCol).Hidden = Columns(EmpToggleCol).Hidden = False
End Sub

Sub TeamLeadShowAndHideColumns()
Columns(TLToggleCol).Hidden = Columns(TLToggleCol).Hidden = False
End Sub

Sub PhoneTimeShowAndHideColumns()
Columns(PTToggleCol).Hidden = Columns(PTToggleCol).Hidden = False
End Sub

Open in new window


I only have problem with this code running when the worksheet is locked.  Is there a line of code that could be interested after the sub starts, and before it finishes to unprotect/protect the worksheet?

Thank you in advance for your help!
LVL 1
GeekamoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

FlysterCommented:
Use ActiveSheet.Unprotect and ActiveSheet.Protect.

Sub EmployeesShowAndHideColumns()
ActiveSheet.Unprotect Password:="Enter_Your_Password_Here"
  Columns(EmpToggleCol).Hidden = Columns(EmpToggleCol).Hidden = False
ActiveSheet.Protect Password:="Enter_Your_Password_Here"
End Sub

Open in new window


Flyster
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GeekamoAuthor Commented:
@ Flyster - What do I do, if I don't use a password?
0
GeekamoAuthor Commented:
@ Flyster - I guess I answered my own question. :)  I just left the password part off of your solution.  Thanks Flyster! :)
0
FlysterCommented:
I should have mentioned that in my original post. Glad it worked for you. Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.