Iamlaosong
Use the VBA program to work with Excel data files. The user's data files are sometimes in their own active filtering mode, often resulting in incorrect data processing. To do this, it is necessary to check whether the worksheet is in this mode, assuming that you remove your own active screening. Statements such as the following:
If Activesheet.autofiltermode = True then Selection.autofilter
This statement is generally used only to remove its own active filter, although Selection.autofilter can also add its own active filter, but the filter location may be in the current cell, so be aware. Add a cell to the field header before you actively filter it. Then use The following statement for example :
If Activesheet.autofiltermode = False then Selection.autofilter
If you are checking other inactive worksheets, you can use the following statement:
If Worksheets ("Sheet1"). AutoFilterMode = True Then
Worksheets ("Sheet1"). Range ("A1"). AutoFilter
attached:Range.autofilter Method
Excel Developer Reference |
|
Filters a list using the AutoFilter.
syntax
expression . AutoFilter (, criteria1 , operator , criteria2 , visibledropdown )
expression An expression of that returns a Range object.
Parameters
Name |
required/optional |
Data Type |
Description |
Field |
Optional |
Variant |
The integer offset of the field on which your want to base the filter (from the "the left" of the list; the leftmost field is Fie LD one). |
Criteria1 |
Optional |
Variant |
the criteria (a string; for example," 101 "). Use ' = ' to the Find blank fields, or use ' <> ' to find nonblank fields. If This argument is omitted, the criteria are all. if Operator is xltop10items , criteria1 specifies the number of items (for example," Ten "). |
Operator |
Optional |
XlAutoFilterOperator |
One of the constants of XlAutoFilterOperator specifying the type of filter. |
Criteria2 |
Optional |
Variant |
The second criteria (a string). Used with Criteria1 and Operator to construct compound criteria. |
Visibledropdown |
Optional |
Variant |
True to display the AutoFilter Drop-down arrow for the filtered field. False to hide the AutoFilter drop-down arrow for the filtered field. True by default. |
Return Value
Variant
Remarks
If you omit all the arguments, this method simply toggles the display of the AutoFilter drop-down arrows in the specified Range.
Example
This example filters a list starting in cell A1 on Sheet1 to display only the entries in which field one are equal to the S Tring "Otis". The Drop-down arrow for field one would be hidden.
Visual Basic for Applications |
Worksheets("Sheet1").Range("A1").AutoFilter _ field:=1, _ Criteria1:="Otis", _ VisibleDropDown:=False
|
VBA Study Worksheet self-active filter mode check