Excel VBA Autofilter not working with Date column

I got a problem using AutoFilter with VBA in Excel.

It works well for regular filters, but filtering the date column does not work as intended.
The column is formatted as date, I can filter it manually and absurdly, if I run my code, it filters nothing but when I check the filter and then only click ok (no change being applied to the filter criteria), it starts filtering correctly.

Here is my code:

ws.ListObjects(SheetName).Range.AutoFilter Field:=3, Criteria1 _
        :=">" & CDate([datecell]), Operator:=xlAnd, Criteria2:= _
        "<=" & CDate(WorksheetFunction.EoMonth([datecell], 3))

Anyone has an idea? It seems to be a common problem, but I have not found a solution.

Thanks in advance.

Edit: Just to add, when I macro record it and run the recorded macro, it does not work either.


(Visited 3 times, 1 visits today)