Export (0) Print
Expand All
Expand Minimize

NamedRange.AutoFilter Method

Filters a list using the AutoFilter.

Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel (in microsoft.office.tools.excel.dll)

public Object AutoFilter (
	[OptionalAttribute] Object Field,
	[OptionalAttribute] Object Criteria1,
	[OptionalAttribute] XlAutoFilterOperator Operator,
	[OptionalAttribute] Object Criteria2,
	[OptionalAttribute] Object VisibleDropDown



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)).


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").


Can be one of the following XlAutoFilterOperator constants:

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


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


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.

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 Understanding Optional Parameters in COM Interop.

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".

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

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

    namedRange1.AutoFilter(1, "Robert",
        Excel.XlAutoFilterOperator.xlAnd, missing, true);

© 2015 Microsoft