VBA:Getting a list of available criteria using autofilter

maxell

New Member
Joined
Mar 23, 2006
Messages
2
I am new to the board but have spent a lot of time "living inside" Excel VBA code. I am trying to find VBA code that lists or "gets" the criteria for each column once autofilter is on.

Is there a VBA function that can do this? Is there a way to "loop" through each criteria and store in an array?

Mike
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
This is a slight modification to the HELP sample for the Object (you need to have active filters, that is you need to select a criteria from at least one AutoFilter to use this code):


Dim w As Worksheet
Dim filterArray()
Dim currentFiltRange As String

Sub ChangeFilters()
Dim myKs

Set w = Worksheets("Sheet1")

With w.AutoFilter
currentFiltRange = .Range.Address

With .Filters
ReDim filterArray(1 To .Count, 1 To 3)

For f = 1 To .Count
With .Item(f)
myKs = myKs & "Filter: " & f & " "

If .On Then
filterArray(f, 1) = .Criteria1
myKs = myKs & "Criteria1: " & filterArray(f, 1) & " "

If .Operator Then
filterArray(f, 2) = .Operator
myKs = myKs & "Operator: " & filterArray(f, 2) & " "

filterArray(f, 3) = .Criteria2
myKs = myKs & "Criteria2: " & filterArray(f, 3) & " "

End If
End If
End With
myKs = myKs & " " & vbLf
Next f
End With
End With
MsgBox myKs

End Sub
 
Upvote 0
Re VBA:Getting a list of available criteria using autofilter

Thanks for the reply.

I was hoping for a way to identify the critier without having to go through and select each one.

The thread link you provided gives me some ideas.

I suspect I will have to loop through the actual list and copy unique entries to another list.

Thanks for the help, and yes - living inside excel does have long term effects - I always seem to want to select active sheets - lol

Mike
 
Upvote 0

Forum statistics

Threads
1,214,426
Messages
6,119,414
Members
448,895
Latest member
omarahmed1

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