I'd like to lock a range of cells (N:W) if the value in cell C of the same row is "Charter" (and this value is chosen from a drop-down list). I'd like to write the code so that this happens for every row.
For example, if C10 = "Charter", N10:W10 would be locked, and if C14 = "Charter", N14:W14 would be locked.
However, if the value in C equals anything other than "Charter", the cells N:W of the corresponding row would be unlocked.
I'd also like to change the default message with a custom message, but I can't figure out how to focus the message on the would be locked cells.
I've attached the code below. Any guidance would be much appreciated.
Private Sub Worksheet_Calculate()
Dim LR As Long, i As Long
LR = Range("C" & Rows.Count).End(xlUp).Row
Me.Unprotect
For i = 1 To LR
With Range("C" & i)
If .Value = "Charter (lite)" Then
Range("N:W").Locked = True
End With
Next i
Me.Protect
Next i
If Intersect(Target, sh.Range("$N:W")) Is Nothing Then Exit Sub
MsgBox "There's no need for data in this cell" & Target.Address
With Application
.EnableEvents = False
.Undo
.EnableEvents = True
End With
End Sub
Bookmarks