A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Hi,
You wrote:
> the Criteria is interpreted as <4/05/2010 (<4-May-2010). Curiously, when I manually select
> the Advanced Filter function directly from the Ribbon (ensuring that the Criteria Range and
> List Range are identical to that defined in the VBA command), the date is interpreted
> correctly. Further, if I execute the above command from the Immediate Window in the VBE,
> the date is once again misinterpreted (by my expectation) as 4-May-2010.
> If I remove the < or > Comparison operator, and use an exact date as the Filer Criteria
> (e.g. 5/04/2010), this date is interpreted correctly using the VBA AdvancedFilter Method.
> Also when I run the same macro using the same data under Excel 2003/WinXP, it behaves just as
> I expect.
> Obviously it is quite simple for me to come up with a work around, but since my code has worked
> so reliably for so long, I would like to know what has changed to cause this anomaly?
I am surprised this has worked before. VBA speaks American when it comes to number and date formatting.
If your cell contains a date when VBA reads the cell, it reads the correct date. It converts the date to
US format internally so to speak, before setting the filter.
If however your cell contains a date concatenated with a > symbol, e.g. >4/5/2009 (4th of may), Excel
reads a STRING, which it then translates into the > and a date *using US syntax*. Your 4th of May becomes
5th of April. Try if changing the date format in the criteria cell to yyyy/mm/dd helps resolve the issue.
Regards, Jan Karel Pieterse|Excel MVP|http://www.jkp-ads.com