Advertisement
dave3009

RudoJasny

Feb 10th, 2022
1,780
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2. Const MyPass As String = "" 'insert sheet protection password
  3. Application.EnableEvents = False ' prevent the event triggering itself
  4. If Not Intersect(Target, Me.Range("B2:F8")) Is Nothing Then ' check if target is in editable range
  5.    If Target.Value = "Z119" Then ' test if target value matches the value to trigger cell lock
  6.        Me.Unprotect MyPass ' remove sheet protection
  7.            Target.Locked = True ' lock the target cell as it meets criteria
  8.        Me.Protect MyPass ' reapply sheet protection
  9.    End If
  10. End If
  11. Application.EnableEvents = True ' turn on event listening
  12. End Sub
  13.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement