XL97: How to Remove Individual AutoFilter Drop-Down Lists

Last reviewed: March 13, 1998
Article ID: Q162049
The information in this article applies to:
  • Microsoft Excel 97 for Windows

SUMMARY

In Microsoft Excel 97, you can programmatically hide an AutoFilter drop- down list for a specific field in a list by using a new argument for the Visual Basic for Applications AutoFilter Method.

This article includes an example Visual Basic macro that hides drop-down lists in a list to which you applied an AutoFilter.

NOTE: The only way to hide individual drop-down lists in a list to which you applied an AutoFilter is to use the AutoFilter method in a macro; you cannot hide the drop-down list manually.

MORE INFORMATION

Syntax for the AutoFilter Method

Use the following syntax for the AutoFilter method:

   <expression>.AutoFilter(Field, Criteria1, Operator, Criteria2,
       Visibledropdown)

where <expression> is an expression that returns a Range object. <Expression> is required for the AutoFilter method. The following table lists the optional arguments for the AutoFilter method and the descriptions for the arguments.

   Argument         Description
   ----------------------------------------------------------------------

   Field            The integer offset of the field on which you want to
                    filter the list (the first field in your list has a
                    value of 1)

   Criteria1        The criteria for filtering the specified field

   Operator         Used to construct compound criteria

   Criteria2        Used in conjunction with Criteria1 and Operator to
                    build compound criteria

   Visibledropdown  True or False; false hides the drop-down list for the
                    specified field

Microsoft provides examples of Visual Basic for Applications procedures 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. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

Sample Macro

  1. Save and close any open workbooks, and then create a new workbook.

  2. In the new workbook, type the following data in Sheet1:

          A1: Name   B1: Area   C1: Amount
          A2: Bob    B2: East   C2: 1
          A3: Sue    B3: West   C3: 2
          A4: Bill   B4: East   C4: 3
          A5: Mary   B5: South  C5: 4
    
    

  3. Start the Visual Basic Editor (press ALT+F11).

  4. On the Insert menu, click Module.

  5. In the module, type the following code:

          Sub Hide_Dropdown()
       
              'Apply an AutoFilter to the list and hide the drop-down list
              'for the second field.
      
              Range("A1").AutoFilter field:=2, Criteria1:="East", _
                  Visibledropdown:=False
       
          End Sub
       
    
6. Run the Hide_Dropdown macro.

  1. Switch to Microsoft Excel (press ALT+F11).

The list in Sheet1 is filtered, and the visible cells are as follows:

   A1: Name   B1: Area   C1: Amount
   A2: Bob    B2: East   C2: 1
   A4: Bill   B4: East   C4: 3

There is no drop-down list for the Area field.

NOTE: The Visibledropdown argument for the AutoFilter method is not listed in the "AutoFilter Method" Help topic. Also, because the AutoFilter method is a write-only method, you cannot programmatically determine which fields in the list have drop-down lists that are hidden or unhidden.

REFERENCES

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

NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If <Product> Help is not installed on your computer, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q120802
   TITLE     : Office: How to Add/Remove a Single Office
               Program or Component


Additional query words: 97 XL97 auto filter auto-filter drop down
Keywords : kbcode kbprg xlvbahowto xlvbainfo xllist
Version : WINDOWS:97
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: March 13, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.