Determine which columns have filter on

  • Thread starter Thread starter Fred Smith
  • Start date Start date
F

Fred Smith

My macro is started after the user has filtered a list.

Is it possible to determine which columns have a filter on? Visually, it's
the ones with a blue down-arrow, but can this be determined
programmatically?
 
Sub FindFilters()
Dim fltr As AutoFilter
Dim f As Filter, i as Long
Set fltr = ActiveSheet.AutoFilter
i = 0
For Each f In fltr.Filters
i = i + 1
If f.On Then
MsgBox "Column " & fltr.Range(0, 0).Offset(0, i - 1).Column
End If
Next

End Sub

i would be the column in the filter range. Example if column D has the
filter and the data starts in B, then i = 3 means the third column in the
filter range (which is D) and the message box would show column 4.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top