VBA Counting Number of AutoFilter Columns

AliCat

Board Regular
Joined
Aug 8, 2002
Messages
82
Is there a way in VBA to count the number of columns holding the filter symbol?
I currently have a Reset macro to remove all filters in one go:
Code:
Selection.AutoFilter Field:= i
and cycle through this a fixed number of times. Some of my sheets may only have 4 columns filtered and some could have as much as 18 (although the're not all aplied at once).
It would be helpful to know one way or the other if this is possible.
Thanks in advance.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
40,436
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
If you just want to remove the filter altogether, you can use:
Code:
Sub ClearFilters()
   With ActiveSheet
      If .AutoFilterMode Then .AutoFilter.Range(1).AutoFilter
   End With
End Sub
or if you simply want to stop filtering, but leave the autofilter set up, you can use:
Code:
Sub ShowAll()
   With ActiveSheet
      If .FilterMode Then .ShowAllData
   End With
End Sub
HTH
 
Upvote 0

AliCat

Board Regular
Joined
Aug 8, 2002
Messages
82
Your method 2 suits just fine I just want to remove multiple filters in one go so that I can start again and was aware that I was looping through filters that might not exist.
Thanks.
 
Upvote 0

Forum statistics

Threads
1,191,686
Messages
5,988,067
Members
440,125
Latest member
vincentchu2369

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
Top