The AutoFilter class represents the filter that is applied to a selected area of cells in a worksheet.

public sealed class AutoFilter

Public NotInheritable Class AutoFilter

To return an AutoFilter object, use Worksheet.AutoFilter.

By default, the filter is not set. If the worksheet doesn't already have a filter, the AutoFilter.Area property will return null. In order to apply the filter to a selected area of cells in the worksheet, the Area property has to be set to an Area object. The designated area has to be on the same worksheet. There can only be one filter in a worksheet. However the area of cells that it is applied to can be changed to different areas of cells within the same worksheet through the AutoFilter.Area property.

The filter will be removed from the worksheet either by calling the filter's Clear() method, by setting the Area property to null, or by deleting all the rows (or just the first row that has the filter headers) or all the columns of the filter from the worksheet.


ExcelApplication xla = new ExcelApplication();
Workbook wb = xla.Create(ExcelApplication.FileFormat.Xlsx);
AutoFilter autoFilter = wb.Worksheets[0].AutoFilter;

Dim xla As New ExcelApplication()
Dim wb As Workbook = xla.Create(ExcelApplication.FileFormat.Xlsx)
Dim autoFilter As AutoFilter = wb.Worksheets(0).AutoFilter

An exception of type ArgumentException will be thrown if the AutoFilter.Area property is set to an area that is on a different worksheet, or an empty area that doesn't have any data in it.

Name

Description

Area

Name

Description

Clear()