HEriksen
Oct 19, 2011, 02:34 AM
I have a problem in a VBA code in Excel 2010.
I try to set a date filter criteria, which is not "equal to", but "is before or equal to" a date defined in a variable named 'Crit_Date'. I use the following VBA line:
Selection.AutoFilter field:=6, Criteria1:="<=" & Crit_Date
The problem is that the filter doesn't show any results even though there are valid data for that criteria.
When I afterwards (after running the macro) go to Excel and press the filter button, and click on "Date Filters" and click on "Custom Filter...", I see that the filter is defined correctly by the macro. When I then hit the "OK" button, the filter seems to work fine.
So the question is: How can I set a criteria using a macro, which doesn't work when running from the macro even though it is set correctly? And what can I do?
I try to set a date filter criteria, which is not "equal to", but "is before or equal to" a date defined in a variable named 'Crit_Date'. I use the following VBA line:
Selection.AutoFilter field:=6, Criteria1:="<=" & Crit_Date
The problem is that the filter doesn't show any results even though there are valid data for that criteria.
When I afterwards (after running the macro) go to Excel and press the filter button, and click on "Date Filters" and click on "Custom Filter...", I see that the filter is defined correctly by the macro. When I then hit the "OK" button, the filter seems to work fine.
So the question is: How can I set a criteria using a macro, which doesn't work when running from the macro even though it is set correctly? And what can I do?