I needed to ensure that no AutoFilters were set before running some other procedures. Below is a very simple sub routine that you can use do reset any, and all, AutoFilters within an Excel Workbook.
'---------------------------------------------------------------------------------------
' Procedure : ResetAutoFilters
' Author : CARDA Consultants Inc.
' Website : http://www.cardaconsultants.com
' Purpose : Resets all the AutoFilter in all the worksheets of the current workbook
' Copyright : The following may be altered and reused as you wish so long as the
' copyright notice is left unchanged (including Author, Website and
' Copyright). It may not be sold/resold or reposted on other sites (links
' back to this site are allowed).
'
' Revision History:
' Rev Date(yyyy/mm/dd) Description
' **************************************************************************************
' 1 2011-December-07 Initial Release
'---------------------------------------------------------------------------------------
Sub ResetAutoFilters()
On Error GoTo Error_Handler
Dim w As Worksheet
For Each w In Worksheets
If w.FilterMode Then w.ShowAllData
Next w
Exit_Error_Handler:
Exit Sub
Error_Handler:
MsgBox "Error Number: " & Err.Number & vbCrLf & _
"Error Description: " & Err.Description & vbCrLf & _
"Error Source: " & "ResetAutoFilters", vbCritical, "An Error Has Occurred"
Resume Exit_Error_Handler
End Sub
Similarily, if you wanted to reset the AutoFilter in one specific worksheet to display all the data, you could use a procedure such as:
'---------------------------------------------------------------------------------------
' Procedure : ResetAutoFilter
' Author : Daniel Pineault, CARDA Consultants Inc.
' Website : http://www.cardaconsultants.com
' Purpose : Reset the AutoFilter in the specified worksheet of the active workbook
' Copyright : The following may be altered and reused as you wish so long as the
' copyright notice is left unchanged (including Author, Website and
' Copyright). It may not be sold/resold or reposted on other sites (links
' back to this site are allowed).
'
' Input Variables:
' ~~~~~~~~~~~~~~~~
' w - Worksheet
'
' Usage:
' ~~~~~~
' ResetAutoFilter sheets("Sheet1") ~ resets a specific sheet named Sheet1
' ResetAutoFilter sheets(6) ~ resets the 6th sheet in the workbook
'
' Revision History:
' Rev Date(yyyy/mm/dd) Description
' **************************************************************************************
' 1 2011-Dec-07 Initial Release
'---------------------------------------------------------------------------------------
Sub ResetAutoFilter(w As Worksheet)
On Error GoTo Error_Handler
If w.FilterMode Then w.ShowAllData
Exit_Error_Handler:
Exit Sub
Error_Handler:
MsgBox "Error Number: " & Err.Number & vbCrLf & _
"Error Description: " & Err.Description & vbCrLf & _
"Error Source: "ResetAutoFilter", vbCritical, "An Error Has Occurred"
Resume Exit_Error_Handler
End Sub