I tried to implement a AdvancedAutoFilter with VBA. This works just fine.
But unfortunately when changing something in the file, to AutoFilter gets de-selected.
I fixed this by using ActiveSheet.ListObjects(1).Range.AutoFilter
But now, everytime I filter and change something in the sheet, to selected filters become forgotten, which is pretty annoying. Is there a workaround for this behavior?
Kind regards
Private Sub Worksheet_Change(ByVal Target As Range)
' Filters LagerlisteHW Row B for the word "Selfservice" and copys the corresponding lines
' to the sheet "Selfservice" to rows with the headers deefined in Selfservice!A2:C2
' Define the search-criteria in Selfservice!L1:L2 (currently the word "Selfservice")
Sheets("LagerlisteHW").Range("B5").CurrentRegion.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=Sheets("Selfservice").Range("L1:L2"), CopyToRange:=Sheets("Selfservice").Range("A2:C2"), Unique:=False
If ActiveSheet.AutoFilterMode = False Then
ActiveSheet.ListObjects(1).Range.AutoFilter
End If
'Selection.AutoFilter ' Enable the AutoFilter Mode
End Sub