The information in this article applies to:
SUMMARYIn Microsoft Excel, you can use the AutoFilter feature to filter a list based on simple criteria. This article contains several sample Microsoft Visual Basic for Applications macros (Sub procedures) for controlling the AutoFilter feature in Excel. MORE INFORMATIONMicrosoft provides programming examples for illustration only, without warranty
either expressed or implied, including, but not limited to, the implied warranties of
merchantability and/or fitness for a particular purpose. This article assumes that you
are familiar with the programming language being demonstrated and the tools used to
create and debug procedures. Microsoft support professionals can help explain the functionality
of a particular procedure, but they will not modify these examples to provide added
functionality or construct procedures to meet your specific needs. If you have limited
programming experience, you may want to contact a Microsoft Certified Solution Provider
or the Microsoft fee-based consulting line at (800) 936-5200. For more information about
Microsoft Certified Solution Providers, please see the following page on the World Wide Web:
http://www.microsoft.com/mcsp/For more information about the support options available from Microsoft, please see the following page on the World Wide Web: http://www.microsoft.com/support/supportnet/overview/overview.aspTo test each of the sample macros in this article, use the following sample data:
Macro with "OR" Criteria for One FieldThe following sample macro displays the records in the list where the items in the Zone field are either "a" or "b".
If you run this macro from the sheet that contains the sample list in this article, your list shows all records, except row 3.
Macro to Turn Off the AutoFilterThe following sample macro turns off the AutoFilter, assuming it is turned on, and displays all the records in the list.NOTE: If the AutoFilter is not on when this macro runs, the macro turns on the AutoFilter, but because no criteria is specified, all records should still appear.
Macro with "AND" Criteria for One FieldThe following sample macro displays the records in the list where the items in the Amount field are greater than or equal to one, but less than four:
If you run this macro from the sheet that contains the sample list, rows 2,
3, and 5 appear.
Macro with Criteria for Two FieldsThe following sample macro specifies criteria for two fields:
If you run this macro from the sheet that contains the sample list, only row 2 appears.
REFERENCESFor more information about the AutoFilter, click the Search button in Help and type: autofilter Additional query words: 5.00a 5.00c 8.00 XL98 XL97 XL7 XL5
Keywords : kbprg kbdta kbdtacode PgmHowto KbVBA |
Last Reviewed: September 14, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |