Hello everyone,
I'm struggling to get this code right. Hopefully someone here can steer me in the right direction and help me out.
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]LOCK[/TD]
[TD]PERSON[/TD]
[TD]DATE[/TD]
[TD]CONTROL no[/TD]
[TD]Value 1[/TD]
[TD]Value 2[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Person 1[/TD]
[TD]01-01-2018[/TD]
[TD]1234[/TD]
[TD]15[/TD]
[TD]55[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Person 2[/TD]
[TD]20-02-2018[/TD]
[TD]5678[/TD]
[TD]20[/TD]
[TD]42[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Person 3[/TD]
[TD]15-04-2018[/TD]
[TD]9012[/TD]
[TD]34[/TD]
[TD]37[/TD]
[/TR]
</tbody>[/TABLE]
Above is a sample of what I'm trying to accomplish, possibly by VBA.
The sheet I'm working with is a password protected sheet, with only the cells unlocked that may have data entered into them.
However, I want the data in the rows to be locked after the first cell in the row (LOCK row) has value YES.
If the data in cell A2 is YES, data in cells B2:F2 cannot be edited anymore. If the data in A2 is NO, editing is possible again.
First time I tried this with Data Validation, but the problem there was the data could not be changed, however the content could be cleared.
I've found some code that worked, but this only works on 1 cell or row. I need it to work for the full sheet, each row independently.
As the sheet might content hundreds of rows, of course I cannot just copy paste the code into oblivion.
The VBA code is tried was as below:
Hope everything is clear, and someone can help me out here.
Thanks in advance.
Kind regards,
Elraw
I'm struggling to get this code right. Hopefully someone here can steer me in the right direction and help me out.
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]LOCK[/TD]
[TD]PERSON[/TD]
[TD]DATE[/TD]
[TD]CONTROL no[/TD]
[TD]Value 1[/TD]
[TD]Value 2[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Person 1[/TD]
[TD]01-01-2018[/TD]
[TD]1234[/TD]
[TD]15[/TD]
[TD]55[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Person 2[/TD]
[TD]20-02-2018[/TD]
[TD]5678[/TD]
[TD]20[/TD]
[TD]42[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Person 3[/TD]
[TD]15-04-2018[/TD]
[TD]9012[/TD]
[TD]34[/TD]
[TD]37[/TD]
[/TR]
</tbody>[/TABLE]
Above is a sample of what I'm trying to accomplish, possibly by VBA.
The sheet I'm working with is a password protected sheet, with only the cells unlocked that may have data entered into them.
However, I want the data in the rows to be locked after the first cell in the row (LOCK row) has value YES.
If the data in cell A2 is YES, data in cells B2:F2 cannot be edited anymore. If the data in A2 is NO, editing is possible again.
First time I tried this with Data Validation, but the problem there was the data could not be changed, however the content could be cleared.
I've found some code that worked, but this only works on 1 cell or row. I need it to work for the full sheet, each row independently.
As the sheet might content hundreds of rows, of course I cannot just copy paste the code into oblivion.
The VBA code is tried was as below:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
ActiveSheet.Unprotect ""
If Range("A2") = "NO" Then
Range("B2:F2").Locked = False
ElseIf Range("A2") = "YES" Then
Range("B2:F2").Locked = True
End If
ActiveSheet.Protect ""
End Sub
Hope everything is clear, and someone can help me out here.
Thanks in advance.
Kind regards,
Elraw