An implementation of Visual Basic that is built into Microsoft products.
Hi @bill gras ,
Thanks for reaching out.
I looked at your macro and the issue comes from two things: a small typo in your code (Criterial should be Criteria1) and the fact that Excel blocks macros from running if there are locked cells. Even though you only locked C2, that’s enough to cause the “Can’t execute code in break mode” message.
Temporarily unprotect the sheet while the macro runs, apply the filter, and then protect it again. Here’s a version you can use:
Sub Hide1Rows()
Dim WS As Worksheet
Set WS = Worksheets("Sit")
' Allow macro to work even with locked cells
WS.Unprotect Password:=""
' Clear any existing filters
If WS.AutoFilterMode Then WS.AutoFilterMode = False
' Filter column KL: hide rows with 1, show everything else
WS.Columns("KL").AutoFilter Field:=1, Criteria1:="<>1"
' Protect sheet again but allow macros to run
WS.Protect Password:="", UserInterfaceOnly:=True
End Sub
Hope this helps! If my answer was helpful - kindly follow the instructions here so others with the same problem can benefit as well.