Private Sub Worksheet_Activate()
If ThisWorkbook.Worksheets("Options").Range("B480").Value = "1" Then
ActiveSheet.Unprotect Password:="123"
ThisWorkbook.Worksheets("Context").Range("F32:F33,L37:L38,T37:T38,V6:V7,V9,F30,T35,N35,F35,N32,Z32,N30,S30,B3:AI305,F35,N32:N33,Z32:Z33,N30,S30,Z30").Locked = True
ActiveSheet.Protect Password:="123", UserInterfaceOnly:=True
Else
ActiveSheet.Unprotect Password:="123"
ThisWorkbook.Worksheets("Context").Range("F32:F33,L37:L38,T37:T38,V6:V7,V9,F30,T35,N35,F35,N32,Z32,N30,S30,B3:AI305,F35,N32:N33,Z32:Z33,N30,S30,Z30").Locked = False
ActiveSheet.Protect Password:="123", UserInterfaceOnly:=True
End If
End Sub
The range to be locked/unlocked includes merged cells and single cells. Initially, the sheet is locked with the password "123" and allows editing only on the range indicated.
Bookmarks