Clear Filters on a tab (table)

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,338
Office Version
  1. 365
Platform
  1. Windows
I have been using the below code to clear filters. But this only works if something is being filtered first, If nothing is filtered and this code is ran, the user gets an error.

Is there another way to do this to avoid the error message? Maybe a way to check if anything is filtered first. Or do you suggest exiting the code on error (which would get difficult because I want to add additional steps to this code - so in the end the code will be doing more than just clearing the cell and filters.

It errors on: ActiveSheet.ShowAllData

Thanks in advance for the help

Code:
Sub ClearTemplat()
'
'Step 1
''' Clear Any Filters

    Sheets("Step 1").Select
    Range("D13").Select
    Selection.ClearContents

    Sheets("Step 1").Select
    Range("D15").Select
    ActiveSheet.ShowAllData
    
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi,
try

VBA Code:
Sub ClearTemplat()
'
'Step 1
''' Clear Any Filters

     With Worksheets("Step 1")
        .Range("D13").ClearContents

     If .FilterMode Then .ShowAllData
     End With
  
End Sub

Dave
 
Upvote 0
Solution
welcome and appreciate feedback

Dave
 
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,394
Members
448,957
Latest member
Hat4Life

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top