Microsoft KB Archive/215770

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Knowledge Base


Article ID: 215770

Article Last Modified on 10/10/2006



APPLIES TO

  • Microsoft Excel 97 Standard Edition



This article was previously published under Q215770


SYMPTOMS

When running a recorded macro that uses the AutoFilter feature, a date that meets the filter criteria is not properly filtered, either appearing when it shouldn't or not appearing when it should.

CAUSE

This behavior occurs when you do the following:

  1. While recording a macro, you use the AutoFilter command.
  2. You select a date for part of the AutoFilter criteria.
  3. You change the date format of the cell used for the criteria.
  4. You run the macro you recorded.


RESOLUTION

Change the value assigned to the Criteria1 argument or the Criteria2 argument of the AutoFilter method to match the date format of the date column on the AutoFilter list.

For example, if the line of code is as follows

Selection.AutoFilter Field:=1, Criteria1:="2/2/98"
                

and the cell containing the date in the AutoFilter list is formatted as m/d/yyyy, change the line of code to the following:

Selection.AutoFilter Field:=1, Criteria1:="2/2/1998"
                

MORE INFORMATION

The AutoFilter feature performs a simple string comparison. When you change the date format of the cell, AutoFilter fails because the string value is now different from the string value recorded for the AutoFilter method.

REFERENCES

For more information about the AutoFilter method, from the Visual Basic Editor, click the Office Assistant, type autofilter method, click Search, and then click to view "AutoFilter Method."



Additional query words: XL97 vba

Keywords: kbdtacode kbprb KB215770