Difference between 2 VBA codes to clear filters

willow1985

Well-known Member
Joined
Jul 24, 2019
Messages
931
Office Version
  1. 365
Platform
  1. Windows
Hello,

I was wanting to know what the difference was between these 2 codes to clear filters? I was given these in the past and was wondering if there was a difference?

Sometimes I want to clear a filter on a table and other times just a standard filter.

Thank you for your help ?

VBA Code:
'Code #1'
If (ActiveSheet.AutoFilterMode And ActiveSheet.FilterMode) Or ActiveSheet.FilterMode Then
  ActiveSheet.ShowAllData
End If

'Code #2'
         Dim lo As ListObject
  For Each lo In ActiveSheet.ListObjects
    lo.AutoFilter.ShowAllData
      Next lo
 

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).
The second one is specifically for a filter used in a named table or list. The first one is for a general worksheet.
 
Upvote 0

Forum statistics

Threads
1,225,666
Messages
6,186,316
Members
453,349
Latest member
neam

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