Controlling Autofilter with VBA - adding criteria to existing filtered column

coloradomtns

New Member
Joined
Apr 14, 2016
Messages
5
Hello all,

I am stuck on an autofilter issue. I am trying to add criteria to an existing filtered column named "Interval".

I have an Excel table with a column containing string or numeric data (see table below).

I need to filter and return all records that are contained in the array (note I do not need to use an array).

The code below only returns records with B1 and 7.

Interval
A1,B1
7,8
B1
A1,C1
2,3,4
6A,6E,6F
A1,B1,2,3,4,5
6A,6B,6C
A1,B1,2,3,4,5,6,7,8
7
2,3,4
2
5,6A,6E,7,8
5

<tbody>
</tbody>

























Here is my code that I'm currently using below. It only returns B1 and 7 - need to see all records containing 6A, B1, and 7.

=========================
Sub Macro5()
Dim i As Long, arr As Variant

arr = Array("6A", "B1", "7")

ActiveSheet.Range("A1:A15").AutoFilter field:=1, Criteria1:=arr, Operator:=xlFilterValues

End Sub

Thanks!
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
i don't think you can autofilter more than 2 criteria at a time. If your filter values are always constant, i suggest you create a helper column (X or Yes or whatever), and filter on that column
 
Upvote 0
Thank you both. I kind of knew that was going to be the answer but I had hopes I was missing something. I abandoned the autofilter approach and used 2 nested FOR loops with 6 nested IF statements. Works perfect - but I'm glad I asked the autofilter question now and have your answers for future reference.
 
Upvote 0
Glad you got it sorted & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,067
Messages
6,122,949
Members
449,095
Latest member
nmaske

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