Expand Minimize
This topic has not yet been rated - Rate this topic

NamedRange.AutoFilter Method

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Filters a list using the AutoFilter.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)
Object AutoFilter(
	Object Field,
	Object Criteria1,
	XlAutoFilterOperator Operator,
	Object Criteria2,
	Object VisibleDropDown
)

Parameters

Field
Type: System.Object

The offset of the field on which you want to base the filter (from the left of the list; the leftmost field is field 1 (one)).

Criteria1
Type: System.Object

The criteria (a string; for example, "101"). Use "=" to find blank fields, or use "<>" to find nonblank fields. If this argument is omitted, the criteria is All. If Operator is xlTop10Items, Criteria1 specifies the number of items (for example, "10").

Operator
Type: Microsoft.Office.Interop.Excel.XlAutoFilterOperator

Can be one of the following XlAutoFilterOperator constants:

xlAnd

xlBottom10Items

xlBottom10Percent

xlOr

xlTop10Items

xlTop10Percent

Use xlAnd and xlOr with Criteria1 and Criteria2 to construct compound criteria.

Criteria2
Type: System.Object

The second criteria (a string). Used with Criteria1 and Operator to construct compound criteria.

VisibleDropDown
Type: System.Object

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

Type: System.Object

If you omit all the arguments, this method simply toggles the display of the AutoFilter drop-down arrows in the NamedRange control.

Optional Parameters

For information on optional parameters, see Optional Parameters in Office Solutions.

The following code example sets cells A1 through A5 to five different name strings and then uses the AutoFilter method to filter for the name "Robert".

This example is for a document-level customization.

private void SetAutoFilter()
{
    this.Range["A1"].Value2 = "Kathleen";
    this.Range["A2"].Value2 = "Robert";
    this.Range["A3"].Value2 = "Paul";
    this.Range["A4"].Value2 = "Harry";
    this.Range["A5"].Value2 = "George";

    Microsoft.Office.Tools.Excel.NamedRange namedRange1 =
        this.Controls.AddNamedRange(this.Range["A1", "A5"],
        "namedRange1");

    namedRange1.AutoFilter(1, "Robert",
        Excel.XlAutoFilterOperator.xlAnd, true);
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.