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?
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.