VBA clear filter with a button

Lolipop

New Member
Joined
May 24, 2023
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I want to create a button to clear the filter. I have a data in excel that link with SAP. I have 10 column of data.
May I know vba code to clear all the filter when there is filter applied?
As you can see in the picture below, I have filter the project. So whenever I click the clear filter button, it will clear all the filter.

Thank you in advance for your kind help.


1686799925393.png
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Assuming your sheet is called "Sheet1" - change to suit

VBA Code:
Sub Clear_Filter()
    If Worksheets("Sheet1").AutoFilterMode Then Worksheets("Sheet1").AutoFilter.ShowAllData
End Sub
 
Upvote 0
Assuming your sheet is called "Sheet1" - change to suit

VBA Code:
Sub Clear_Filter()
    If Worksheets("Sheet1").AutoFilterMode Then Worksheets("Sheet1").AutoFilter.ShowAllData
End Sub
I've change the sheet name but it's not working.
 
Upvote 0
Your data appears to be using an Excel table which in VBA is referred to as a List Object.
If that is the cased try this, just put in your Table Name where it says Table1

VBA Code:
Sub RemoveFilter()

    Dim lo As ListObject
    
    Set lo = ActiveSheet.ListObjects("Table1")      ' <--- Change to your table name
    If lo.ShowAutoFilter = True Then
        lo.AutoFilter.ShowAllData
    End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,419
Messages
6,124,796
Members
449,189
Latest member
kristinh

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