|The code below will Unprotect the worksheet so that the filter can be applied and then Protect the worksheet again.|
The first thing you need to do is Unlock A1:B1 via the Format Cells...Protection tab so that users can enter data in those cells. Then you can Protect the worksheet, choosing whatever options that you require.
As written, the code uses zzzzz as the password. You can change that to whatever you want, or eliminate the Password:="zzzzz" from both instructions if you don't want to password protect the sheet. If the protection is just to prevent accidental changes to the data, as opposed to malicious changes, then using a password is up to you.
If you do want to use a password to protect the sheet, you should also consider using a password to protect the VBA code. If you don't, then users will be able to see (and change) not only the password, but the code itself. This link explains how to protect the VBA code so users can't even see it.
Here is the revised code, with the protection instructions included.
Private Sub Worksheet_Change(ByVal Target As Range)
'If change is made to A1 or B1, filter A3:P400 based on those 2 cells
If Target.Address = "$A$1" Or Target.Address = "$B$1" Then
ActiveSheet.Range("$A$3:$P$400").AutoFilter Field:=1, Criteria1:=Range("A1")
ActiveSheet.Range("$A$3:$P$400").AutoFilter Field:=16, Criteria1:=Range("B1")
Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.