• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

block specific sheets

Marco1975

New Member
Hi, I would like to block 3 sheets specific , but the macro doesn't work ; surely there is a mistake , but I can't find it . Can anyone help me to modify this macro ? Thanks .

Code:
Sub block()


Dim wsh As Worksheet
Sheets(Array("foglio1", "foglio2", "foglio3")).Select
For Each wsh In ActiveWindow.SelectedSheets
   
  wsh.Protect Password:="pippo", _
  UserInterFaceOnly:=True
  EnableSelection = xlUnlockedCells
   
Next wsh
     
End Sub
 
Hi Marco,

I'm not sure but I think you can't protect with a sheet array. EnableSelection is not an argument of Protect method.
Try this way :
Code:
Public Sub Macro1()
Dim TF As Variant
Dim I as Byte

TF = Array("Foglio1", "Foglio2", "Foglio3")
For I = 0 To UBound(TF, 1)
    With Sheets(TF(I))
        .Protect Password:="pippo", UserInterFaceOnly:=True
        .EnableSelection = xlUnlockedCells
    End With
Next I
End Sub
 
Back
Top