Here's a simplified model of my task:
I would like to filter this table to show only the entries after 22-Jul. I can get the expected result if I manually apply a filter and use the following values in the menus / dialog box:
- "Date Filters"
- "After..."
- "is after" and "22/7/2020"
But when I use this code (starting with the autofilter turned off) ...
Dim xx As Date
xx = Cells(4, 1)
ActiveSheet.Range("$A:$B").AutoFilter Field:=1, Criteria1:=">" & xx, Operator:=xlAnd
... excel filters out ALL the rows.
Trying to debug, if I click the autofilter drop down button in column A, it looks like Excel populated exactly the same options as I had done manually ... and if I click through to the dialog box and click OK (without changing anything at all), the filter behaves as expected.
Is there any way I can make VBA apply the autofilter correctly?
In the actual application, I only need simple functionality (apply different colours before / after a cutoff date). Worst case I could add a temporary Boolean column to the sheet and filter on that... but I'd be very grateful if someone could suggest a less clumsy method.
ActiveSheet.Range("$A:$c").AutoFilter Field:=3, Criteria1:="True", Operator:=xlAnd
If relevant, I'm in the United Kingdom with regional default date format = DD/MM/YY.




Sub Macro3()Columns("A:B").SelectSelection.AutoFilterActiveSheet.Range("$A$1:$B$6").AutoFilter Field:=1, Criteria1:= ">22/07/2020", Operator:=xlAndEnd SubSince it gave the same results as my original posted code I assumed that it would not be useful to post the code (sufficient to say that the behaviour is the same). However, by prompting me to play with the code again, your question has helped me find my own solution which I am about to post below! - LondonJustin