kwatt562
asked on
Lock cells vba
Got a sheet where order entry is entered in each row, column Z of the row, "approved" is entered. When approved is entered against the order I want the worksheet to lock that row and then protect the sheet.The next orders can then be entered and each time "approved is entered in that rows column z, the row should lock.
My code is
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = "26" Then
If UCase(Target.Value) = "Approved" Then
ActiveSheet.Unprotect
Target.EntireRow.Locked = True
Target.Locked = True
ActiveSheet.Protect
End If
End If
End Sub
Bur I cant quite get it too work correctly
My code is
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = "26" Then
If UCase(Target.Value) = "Approved" Then
ActiveSheet.Unprotect
Target.EntireRow.Locked = True
Target.Locked = True
ActiveSheet.Protect
End If
End If
End Sub
Bur I cant quite get it too work correctly
Also, you don't need both:
Target.EntireRow.Locked = True
Target.Locked = True
Just:
Target.EntireRow.Locked = True
Kevin
Target.EntireRow.Locked = True
Target.Locked = True
Just:
Target.EntireRow.Locked = True
Kevin
ASKER
Thanks for your comments but it still fails to lock the rows and protect the sheet
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yeah that was it, couldnt seee the wood for the trees, thanks for pointing it out
Thanks for the points, but I think you should acknowledge others' contributions too.
ASKER
Appreciate everyones comments, but the "" resolution is not needed as it works with quotes on, likewise the removal Target.Locked = True doesnt effect anything it just cleans it up. Thats why I gave you all the points as you pointed out my error which was preventing the code from running.
Regards
Regards
If Target.Column = "26" Then
Like this:
If Target.Column = 26 Then