officefileapi-113769-spreadsheet-document-api-examples-filter-data-how-to-clear-a-filter.md
The examples below demonstrate how to clear or disable a filter to redisplay all the rows in the filtered range.
To remove a filter from a specific column, access this column by its index in the AutoFilterColumnCollection collection, and then call the AutoFilterColumn.Clear method.
// Enable filtering for the specified cell range.
CellRange range = worksheet["B2:E23"];
worksheet.AutoFilter.Apply(range);
// Filter values in the "Sales" column that are greater than 5000$.
worksheet.AutoFilter.Columns[2].ApplyCustomFilter(5000, FilterComparisonOperator.GreaterThan);
// Remove the filter from the SALES column.
worksheet.AutoFilter.Columns[2].Clear();
' Enable filtering for the specified cell range.
Dim range As CellRange = worksheet("B2:E23")
worksheet.AutoFilter.Apply(range)
' Filter values in the "Sales" column that are greater than 5000$.
worksheet.AutoFilter.Columns(2).ApplyCustomFilter(5000, FilterComparisonOperator.GreaterThan)
' Remove the filter from the SALES column.
worksheet.AutoFilter.Columns(2).Clear()
To clear all the filters specified in a worksheet, use the AutoFilterBase.Clear method of the SheetAutoFilter object.
Worksheet worksheet = workbook.Worksheets["Regional sales"];
workbook.Worksheets.ActiveWorksheet = worksheet;
// Enable filtering for the specified cell range.
CellRange range = worksheet["B2:E23"];
worksheet.AutoFilter.Apply(range);
// Filter values in the "Sales" column that are greater than 5000$.
worksheet.AutoFilter.Columns[2].ApplyCustomFilter(5000, FilterComparisonOperator.GreaterThan);
// Clear the filter.
worksheet.AutoFilter.Clear();
Dim worksheet As Worksheet = workbook.Worksheets("Regional sales")
workbook.Worksheets.ActiveWorksheet = worksheet
' Enable filtering for the specified cell range.
Dim range As CellRange = worksheet("B2:E23")
worksheet.AutoFilter.Apply(range)
' Filter values in the "Sales" column that are greater than 5000$.
worksheet.AutoFilter.Columns(2).ApplyCustomFilter(5000, FilterComparisonOperator.GreaterThan)
' Clear the filter.
worksheet.AutoFilter.Clear()
To disable the filtering functionality, use the AutoFilterBase.Disable method of the SheetAutoFilter object. In this case, all the specified filters are removed, and the drop-down arrows disappear from the column headers in the filtered range.
Worksheet worksheet = workbook.Worksheets["Regional sales"];
workbook.Worksheets.ActiveWorksheet = worksheet;
// Enable filtering for the specified cell range.
CellRange range = worksheet["B2:E23"];
worksheet.AutoFilter.Apply(range);
// Disable filtering for the entire worksheet.
worksheet.AutoFilter.Disable();
Dim worksheet As Worksheet = workbook.Worksheets("Regional sales")
workbook.Worksheets.ActiveWorksheet = worksheet
' Enable filtering for the specified cell range.
Dim range As CellRange = worksheet("B2:E23")
worksheet.AutoFilter.Apply(range)
' Disable filtering for the entire worksheet.
worksheet.AutoFilter.Disable()
See Also