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
kwatt562Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jppintoCommented:
Please try removing the "" from this:

If Target.Column = "26" Then

Like this:

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

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

Just:

        Target.EntireRow.Locked = True

Kevin
0
kwatt562Author Commented:
Thanks for your comments but it still fails to lock the rows and protect the sheet
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

StephenJRCommented:
And this must be

If UCase(Target.Value) = "APPROVED"

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kwatt562Author Commented:
Yeah that was it, couldnt seee the wood for the trees, thanks for pointing it out
0
StephenJRCommented:
Thanks for the points, but I think you should acknowledge others' contributions too.
0
kwatt562Author Commented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.