I am using an AutoFilter with VBA in Excel that works for regular filters, but not a column formatted as date.
I can filter it manually. If I run my code, it filters
SO this worked for me pretty clean
ActiveSheet.Range("$A$1:$K$35727").AutoFilter Field:=1, Criteria1:= _
">=" & Range("G1"), Operator:=xlAnd, Criteria2:="<=" & Range("H1")
You can try this as well
Expected output will start date in my G1 cell and end date will be H1 cell.
you need to convert the format to the american format, like: ">" & Format([datecell], "mm/dd/yyyy") VBA does not understand another format.
Match your "dd-mm-yyy" to the format of the column, so if you have "16-Aug-16" as your source data formatting then make the filter as "dd-mmm-yy"
Dates can be tricky with Excel VBA AutoFilter. Some find it easier to just loop through the array to be filtered.
Sometimes I have found that one can use the numeric value of the date, especially when dealing with "dates between"
Criteria1:= ">" & CDbl([datecell])
Criteria2:= "<=" & CDbl(WorksheetFunction.EoMonth([datecell], 3))
Note that the above need to be "real dates" and not strings that look like dates. Even a single "string date" will mess things up.
This syntax works for me:
.AutoFilter Field:=2, Operator:=xlFilterValues, Criteria2:=Array(2, Format(Now, "yyyy-mm-dd"))
Hint obtained through a macro registration
here's the occam's razor solution... try putting this in Autoopen for the spreadsheet or if you need to, modify it for the sheet that you wish to affect. it will cause the drop down filters for the date headers to appear as individual dates and not as a date hierarchy.
ActiveWindow.AutoFilterDateGrouping = False