SOLVED

Testing to Determine IF a Filter is active

Copper Contributor

I'm working on a spreadsheet that consists of two sheets - a "Transaction Log" that contains a list of expense records.  The second sheet is titled "New Summary" and is basically a "dashboard" that displayed summarized totals.   The "Dashboard" includes a number of buttons - each of which executes a Macro that places a filter on the Transaction log that displays just the records associated with the "drill down" selected.   

 

I've added a button titled "Clear Filters and Return" on the Transaction Log that fires off the following code snippet - which clears the filter - returns the user to the "New Summary" sheet.   This all works exactly as I want it to EXCEPT in instances that the "Clear Filters and Return" button is selected when no filter is active on the Transaction log.   Executing this block of code when no filter is in effort generates a "1004 Run Time Error".   

 

     Sub ClearAndReturn()
     'ActiveSheet.ShowAllData
     Sheets("New Summary").Select
     End Sub

 

Can somebody tell me how test to determine IF a filter is in effort prior to issuing the "ActiveSheet.ShowAllData" command?  

2 Replies
best response confirmed by SpaceNorman (Copper Contributor)
Solution

@SpaceNorman 

Try

    If ActiveSheet.FilterMode Then
        ActiveSheet.ShowAllData
    End If

or

    On Error Resume Next
    ActiveSheet.ShowAllData
    On Error GoTo 0
I went the "If Then" route (Figuring it was better to avoid generating the error in the first place) and it solved my problem! Thank you for the quick feedback! Your help is truly appreciated.
1 best response

Accepted Solutions
best response confirmed by SpaceNorman (Copper Contributor)
Solution

@SpaceNorman 

Try

    If ActiveSheet.FilterMode Then
        ActiveSheet.ShowAllData
    End If

or

    On Error Resume Next
    ActiveSheet.ShowAllData
    On Error GoTo 0

View solution in original post