sdkorin
New Member
- Joined
- Feb 1, 2018
- Messages
- 22
- Office Version
- 2016
- Platform
- Windows
I am trying to lock a row based on the value of the first cell. I've got my VBA working fine for one row, but I need to apply this to multiple rows, all independently.
This works for my single row. I just need this to work exactly the same, but independently for each row, for rows 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, and 37.
This is obviously now working, but this gives you the idea of what I'm looking for.
Thoughts? Thank you for the help.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A13") = "CES" Or Range("A13") = "CES Start" Or Range("A13") = "CES End" Then
Range("D13:CA13").Locked = False
ElseIf Range("A13") = "" Then
Range("D13:CA13").Locked = True
End If
End Sub
This works for my single row. I just need this to work exactly the same, but independently for each row, for rows 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, and 37.
This is obviously now working, but this gives you the idea of what I'm looking for.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A13") = "CES" Or Range("A13") = "CES Start" Or Range("A13") = "CES End" Then
Range("D13:CA13").Locked = False
ElseIf Range("A13") = "" Then
Range("D13:CA13").Locked = True
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A15") = "CES" Or Range("A15") = "CES Start" Or Range("A15") = "CES End" Then
Range("D15:CA15").Locked = False
ElseIf Range("A15") = "" Then
Range("D15:CA15").Locked = True
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A17") = "CES" Or Range("A17") = "CES Start" Or Range("A17") = "CES End" Then
Range("D17:CA17").Locked = False
ElseIf Range("A17") = "" Then
Range("D17:CA17").Locked = True
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A19") = "CES" Or Range("A19") = "CES Start" Or Range("A19") = "CES End" Then
Range("D19:CA19").Locked = False
ElseIf Range("A19") = "" Then
Range("D19:CA19").Locked = True
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A21") = "CES" Or Range("A21") = "CES Start" Or Range("A21") = "CES End" Then
Range("D21:CA21").Locked = False
ElseIf Range("A21") = "" Then
Range("D21:CA21").Locked = True
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A23") = "CES" Or Range("A23") = "CES Start" Or Range("A23") = "CES End" Then
Range("D23:CA23").Locked = False
ElseIf Range("A23") = "" Then
Range("D23:CA23").Locked = True
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A25") = "CES" Or Range("A25") = "CES Start" Or Range("A25") = "CES End" Then
Range("D25:CA25").Locked = False
ElseIf Range("A25") = "" Then
Range("D25:CA25").Locked = True
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A27") = "CES" Or Range("A27") = "CES Start" Or Range("A27") = "CES End" Then
Range("D27:CA27").Locked = False
ElseIf Range("A27") = "" Then
Range("D21:CA27").Locked = True
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A29") = "CES" Or Range("A29") = "CES Start" Or Range("A29") = "CES End" Then
Range("D29:CA29").Locked = False
ElseIf Range("A29") = "" Then
Range("D29:CA29").Locked = True
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A31") = "CES" Or Range("A31") = "CES Start" Or Range("A31") = "CES End" Then
Range("D31:CA31").Locked = False
ElseIf Range("A31") = "" Then
Range("D31:CA31").Locked = True
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A33") = "CES" Or Range("A33") = "CES Start" Or Range("A33") = "CES End" Then
Range("D33:CA33").Locked = False
ElseIf Range("A33") = "" Then
Range("D33:CA33").Locked = True
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A35") = "CES" Or Range("A35") = "CES Start" Or Range("A35") = "CES End" Then
Range("D35:CA35").Locked = False
ElseIf Range("A35") = "" Then
Range("D35:CA35").Locked = True
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A37") = "CES" Or Range("A37") = "CES Start" Or Range("A37") = "CES End" Then
Range("D37:CA37").Locked = False
ElseIf Range("A37") = "" Then
Range("D37:CA37").Locked = True
End If
End Sub
Thoughts? Thank you for the help.