Is it possible to protect/unprotect multple sheets

Pauljj

Well-known Member
Joined
Mar 28, 2004
Messages
2,035
I have 8 sheets that sometimes need to be protected and unprotected at the same time, is there a more efficient way to do this then going to every single sheet and doing this one at a time ??

Cheers


Paul
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

HalfAce

MrExcel MVP
Joined
Apr 6, 2003
Messages
9,454
Hello Pauljj,
Here's something you can do.
Put a command button (from the Controls Toolbox toolbar) on one of your sheets somewhere.
Change the caption on the button to "Protect Sheets" (without the quotes).
Then paste this code into the sheet module of the sheet your command button is on.
(Assumes you want to protect/unprotect all sheets in the workbook with no exceptions.)
Code:
Private Sub CommandButton1_Click()
Dim Ws As Worksheet
Application.ScreenUpdating = False

If CommandButton1.Caption = "Protect Sheets" Then
  For Each Ws In ThisWorkbook.Worksheets
    Ws.Protect
  Next Ws
  CommandButton1.Caption = "Unprotect Sheets"
Else
  For Each Ws In ThisWorkbook.Worksheets
    Ws.Unprotect
  Next Ws
  CommandButton1.Caption = "Protect Sheets"
End If

Application.ScreenUpdating = True
End Sub
 

Forum statistics

Threads
1,136,268
Messages
5,674,732
Members
419,523
Latest member
Urnovio

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top