Protect all sheets less Summary

healey21

Well-known Member
Joined
Dec 22, 2009
Messages
900
I have been asked to create VBA code to help a user to password protect all sheets in a workbook less the Summary sheet. The workbook sometimes has 20 sheets and other times 45 sheets.

I have the following code which will allow me to protect all sheets but how do I exclude the Summary sheet. I am suggesting a range of cells are left unprotected so my users can edit them. So in my code I need to add the password and make sure the Summary sheet isn't included.

Sub mcrProtect3()
Dim i As Integer
' Loop through all sheets in the workbook.
For i = 1 To Sheets.Count
With Sheets(i)
.Range("D4:K26").Locked = False
.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End With
Next i
End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Try

Code:
Sub ProtectIt()
  For Each ws in ActiveWorkbook.Worksheets
    If ws.Name <> "Summary" Then
      ws.protect Password:= "My Password"
    End if
  Next ws
End Sub
 
Upvote 0
Here it is with the rest of your code included.

Code:
Sub mcrProtect3()
For Each ws in ActiveWorkbook.Worksheets
   If ws.Name <> "Summary Name" Then
       ws.Range("D4:K26").Locked = False
       ws.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
   End If
Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

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
Back
Top