Protect Multiple Sheet at once

glynn1969

Board Regular
Joined
Nov 24, 2018
Messages
88
Office Version
  1. 365
Platform
  1. Windows
Hello

Is it possible to apply a vba protect multiple sheets at once? (I have the VBA already - kindly supplied on this site)

Thank you
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
To protect all sheets in a workbook:
Code:
Sub ProtectSheets()
    Application.ScreenUpdating = False
    Dim ws As Worksheet
    For Each ws In Sheets
        ws.Protect
    Next ws
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thank you

I am trying to combine with the macro below which ask the user to select which cells to protect.

My workbook has 5 sheets - sheet1,sheet2, etc and i want to protect the same cells on sheet2, sheet3, etc but not sheet1.



Sub ProtectRange()
Dim Rng As Range
ActiveSheet.Unprotect
Set Rng = Application.InputBox("Type or select the range to protect:", Type:=8)
Cells.Locked = False
Rng.Locked = True
ActiveSheet.Protect
End Sub
 
Upvote 0
Code:
Sub ProtectRange()
  Dim r             As Range
  Dim sAdr          As String
  Dim i             As Long
  Dim wks           As Worksheet

  Set r = Application.InputBox("Type or select the range to protect:", Type:=8)
  sAdr = r.Address

  For i = 2 To Worksheets.Count
    Set wks = Worksheets(i)
    With wks
      .Unprotect
      .Cells.Locked = False
      .Range(sAdr).Locked = True
      .Protect
    End With
  Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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