Search code examples
excelvbafilterlocked

Excel VBA - Filter data that is locked with password


I've been stuck for days on the following:

I'd like to lock data with a password in specific rows and then still be able to use a filter on this data.

enter image description here

This is what i got so far but for some reason it does not work.

Any input would be very welcome!!!

If logbook.Cells(row_index, 1) <> "" Then
    ActiveSheet.Unprotect password:="mypassword"
    logbook.Cells(row_index, 11).Value = "YES"
    logbook.Cells(row_index, 1).EntireRow.Locked = True
    ActiveSheet.Protect password:="mypassword", AllowFiltering:=True         
Else
    Unload Me
End If

Solution

  • If you need to change the data through VBA, you dont need to unprotect it.

    Simply use UserInterfaceOnly:=True and by using AllowFiltering:=True you can still filter your data. Like this:

    ActiveSheet.Protect Password:="mypassword", AllowFiltering:=True, UserInterfaceOnly:=True