Counting the number of columns that have a filter applied?

JugglerJAF

Active Member
Joined
Feb 17, 2002
Messages
297
Office Version
  1. 365
Platform
  1. Windows
Is it possible in VBA to write some code that will return the number of columns within the current region of the active cell that have a filter applied to them?

Example: I have data from A1:E35 and filters applied to column B for one value, and column D for another value. In this instance I'd want to return a value of 2 as there are filters applied to 2 columns (B and D).

I'm not looking to count the number of rows returned by the filter, just the number of columns that have a filter applied to them.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Try:

VBA Code:
Option Explicit
Sub test()
Dim count&, i&
If ActiveSheet.AutoFilterMode Then
    With ActiveSheet.AutoFilter
        For i = 1 To .Filters.count
            If .Filters(i).On Then count = count + 1
        Next
    End With
End If
Debug.Print count
End Sub
 
Upvote 0
Solution
Thanks bebo - I was trying things like "HasFilter" and "IsFiltered" without any luck! Marked your reply as solution. Much appreciated!
 
Upvote 0

Forum statistics

Threads
1,213,484
Messages
6,113,920
Members
448,533
Latest member
thietbibeboiwasaco

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