Hi all,

Currently, my code locks cells depending on the value of a specific cell in Range("D52:O52"). When this code is inserted into the sheet module it works perfectly. At present this is OK, as I run the main locking code from the standard module which calls each piece of code from each sheet to lock it. However, this looks messy when the users click on the macro section in developer tool bar and see sheet1.LockUnlock

I decided to remove all the code from the sheet modules and place it in the same standard module as the parent locking code as a private sub (so I could still call it whilst it removed all references to sheet1.LockUnlock from the macro section in the developer tool bar)

The only problem here is that I now get Unable to set the locked property of the range class. It is exactly the same code which works when inserted into the correct sheet module. If anyone could offer any assistance with this I would greatly appreciate it. Please see code below.

Regards,


Private Sub Lock_Unlock1()
  
   Dim icell As Range
   Dim YearA As Range
   Dim YearF As Range
   Dim Wks As Worksheet
   
   Set YearA = Sheets("Validation").Range("I2")
   Set YearF = Sheets("Validation").Range("J2")
   Set Wks = Sheets("Template")
   
Wks.Unprotect Password:=PackPassword

With Wks

    For Each icell In Wks.Range("D52:O52")

        If icell.Value = YearA Then

            icell.EntireColumn.Locked = True

        ElseIf icell.Value = YearF Then

            Range(Cells(60, icell.Column), Cells(61, icell.Column)).Locked = False '<<<<<<< Error is here
            Range(Cells(64, icell.Column), Cells(67, icell.Column)).Locked = False
            Range(Cells(93, icell.Column), Cells(93, icell.Column)).Locked = False

        End If
    
    Next icell

End With

Wks.Protect Password:=PackPassword, UserInterfaceOnly:=True
    EnableOutlining = True

End Sub