title: Lock Adjacent cell if cell contains certain text
body: <p>I am trying to adapt the following code to lock adjacent cells when Column M contains "NO"</p>
  
  <p>For example if M12 contains "NO", I would like to lock "V12:AG12,AI12:AT12" </p>
  
  <pre><code>Private Sub Worksheet_Change(ByVal Target As Range)
  Dim rng1 As Range
  Dim c As Range
  Set rng1 = Intersect(Target, Range("M:M"))
  If rng1 Is Nothing Then Exit Sub
  ActiveSheet.Unprotect Password:="Password"
  
  With Application
  .ScreenUpdating = False
  .EnableEvents = False
  End With
  
  For Each c In rng1
      Select Case LCase(c.Value)
          Case Is = "YES"
          ActiveSheet.Unprotect Password:="Password"
          Cells(c.Row, 13).Resize(1, 12).Locked = False
          Range(Cells(c.Row, "V"), Cells(c.Row, "AG")).Locked = False
          Range(Cells(c.Row, "AI"), Cells(c.Row, "AT")).Locked = False
           ActiveSheet.Protect Password:="Password"
      Case Is = "NO"
          ActiveSheet.Unprotect Password:="Password"
          Range(Cells(c.Row, "V"), Cells(c.Row, "AG")).Locked = True
          Range(Cells(c.Row, "AI"), Cells(c.Row, "AT")).Locked = True
          ActiveSheet.Protect Password:="Password"
      Case Else
          ActiveSheet.Unprotect Password:="Password"
          MsgBox "Please only input YES or NO in this column", vbCritical +   vbOKOnly
          ActiveSheet.Protect Password:="Password"
          Exit Sub
  End Select
  Next c
  
  With Application
  .ScreenUpdating = True
  .EnableEvents = True
  End With
  ActiveSheet.Protect Password:="Password"
  End Sub
  </code></pre>
  
  <p>However I am confused to <strong>where i would insert the condition "NO" in the above code and also how to select the range to "Lock"</strong> </p>
  
  <p>Attached a picture to demonstrate what I am trying to achieve. <a href="https://i.stack.imgur.com/VBtoj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VBtoj.png" alt="enter image description here"></a></p>
  
  <p>Thanks</p>