Store active Autofilter criteria in array or range

Yard

Well-known Member
Joined
Nov 5, 2008
Messages
1,929
Hi all,

I want to perform some operations (basically a secondary filter) based on the values which are currently filtered within a single filter column.

Code:
.Autofilter.Filters(n).Criteria1
and
Code:
.Criteria2

are great, but what if there are more than 2???

i.e. I have a column containing values L01 to L20.

My column is filtered on L05, L06 and L07 (or some other combination).

I want to extract the values and L05, L06 and L07 and do what I will with them.

What am I missing??

Thanks
 
This is the general idea with collections:

Code:
Sub Get_Uniques()
Dim coll As New Collection
Dim i As Long, cell As Range, temp As String
On Error Resume Next
For Each cell In ActiveSheet.AutoFilter.Range.Columns(1).Offset(1).SpecialCells(xlCellTypeVisible)
    If cell.Value <> "" Then
        coll.Add cell.Value, CStr(cell.Value)
    End If
Next cell
For i = 1 To coll.Count
    temp = temp & vbCrLf & coll(i)
Next
MsgBox "You have " & coll.Count & " unique items whose values are:" & temp
End Sub

which iterates thru the items in the first column of the autofilter range.
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Awesome.

*rushes off, moistened, and forgets about this project and immediately starts applying new knowledge to other things*


**rushes back to PC in the hope that Rory has found some property of the Excel 2007 Autofilter**
 
Upvote 0
Sorry, I thought from your last post you had fixed the problem. Is that not the case?
 
Upvote 0
Hmm it does read like that, doesn't it? :rolleyes:

I can certainly use Richard's solution to give me what I need, but am still curious (=frustrated) about my inability to interrogate the settings within the 2007 Autofilter itself. The multiple selections must exist in the application somewhere....but where?

I'm guessing that on larger sets of data, extracting the Autofilter criteria must be quicker than looping through every cell which has been filtered, hence my thirst for knowledge...
 
Upvote 0
I think you set them by specifying an array of values for criteria1 so it may be that that returns an array or delimited string?
 
Upvote 0
Necro answer:
Code:
                    .AutoFilter Field:=wkColumn, Criteria1:=Array( _
                        param2, _
                        param3, _
                        param4), _
                        Operator:=xlFilterValues
 
Upvote 0

Forum statistics

Threads
1,215,514
Messages
6,125,271
Members
449,219
Latest member
daynle

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