Avatar of kwatt562
kwatt562Flag for United Kingdom of Great Britain and Northern Ireland

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
Microsoft Excel

Avatar of undefined
Last Comment
kwatt562
Avatar of jppinto
jppinto
Flag of Portugal image

Please try removing the "" from this:

If Target.Column = "26" Then

Like this:

If Target.Column = 26 Then
Avatar of zorvek (Kevin Jones)
Also, you don't need both:

        Target.EntireRow.Locked = True
        Target.Locked = True

Just:

        Target.EntireRow.Locked = True

Kevin
Avatar of kwatt562
kwatt562
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Thanks for your comments but it still fails to lock the rows and protect the sheet
ASKER CERTIFIED SOLUTION
Avatar of StephenJR
StephenJR
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of kwatt562
kwatt562
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Yeah that was it, couldnt seee the wood for the trees, thanks for pointing it out
Avatar of StephenJR
StephenJR
Flag of United Kingdom of Great Britain and Northern Ireland image

Thanks for the points, but I think you should acknowledge others' contributions too.
Avatar of kwatt562
kwatt562
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Microsoft Excel
Microsoft Excel

Microsoft Excel topics include formulas, formatting, VBA macros and user-defined functions, and everything else related to the spreadsheet user interface, including error messages.

144K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo