Quick Question - Why isn't this simple code working [locked/protection]

Grizlore

Active Member
Joined
Aug 22, 2006
Messages
259
Hi, i am sure this is something simple.

Could anyone tell me why this code isnt working please?

Basically, i should lock the entire row IF the word "completed" is in column "O"


Code:
Sub Lock_Completed()

Application.ScreenUpdating = False

    With Sheets("AUDITS")
    .Unprotect "password"
    .Cells.Locked = True
        With .Columns("O")
        .AutoFilter Field:=1, Criteria1:="<>Completed"
        On Error Resume Next
        .SpecialCells(xlCellTypeVisible).EntireRow.Locked = True
        On Error GoTo 0
        End With
    .ShowAllData
    .Protect "password"
    End With

Application.ScreenUpdating = True

End Sub

Any help would be appreciated
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
You are locking everything (.cells.locked = true) and then you are locking the entire row of the cells where completed is NOT true.

Try:

Code:
Sub Lock_Completed()

Application.ScreenUpdating = False

    With Sheets("AUDITS")
    .Unprotect "password"
    .Cells.Locked = False
        With .Columns("O")
        .AutoFilter Field:=1, Criteria1:="Completed"
        On Error Resume Next
        .SpecialCells(xlCellTypeVisible).EntireRow.Locked = True
        On Error GoTo 0
        End With
    .ShowAllData
    .Protect "password"
    End With

Application.ScreenUpdating = True

End Sub
 
Upvote 0
Thanks

That code only locks the header row? (the cell O1 is named "OUTSTANDING / COMPLETED")


Can't work out why that is this is happening

any ideas?
 
Upvote 0
It locks all completed rows when I tried it :(

Is your first filter on column O? .AutoFilter Field:=1 will put an auto filter on the first field with a filter (if that makes sense).
 
Upvote 0
we are getting somewhere.... :)

if I change to...
Code:
    .AutoFilter Field:=15, Criteria1:="completed"
then it work. :)

However, i would like to allow the filters to work (so you can select them) however the code doenst allow this. Would you happen to have thoughts on why?

Many thanks for your help, much appreciated :)
 
Upvote 0
Change the .Protect "password" to:

Code:
    .Protect "password", AllowFiltering:=True
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top