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.

[TABLE="class: grid, width: 50, align: left"]
<tbody>[TR]
[TD]Interval
[/TD]
[/TR]
[TR]
[TD]A1,B1
[/TD]
[/TR]
[TR]
[TD]7,8
[/TD]
[/TR]
[TR]
[TD]B1
[/TD]
[/TR]
[TR]
[TD]A1,C1
[/TD]
[/TR]
[TR]
[TD]2,3,4
[/TD]
[/TR]
[TR]
[TD]6A,6E,6F
[/TD]
[/TR]
[TR]
[TD]A1,B1,2,3,4,5
[/TD]
[/TR]
[TR]
[TD]6A,6B,6C
[/TD]
[/TR]
[TR]
[TD]A1,B1,2,3,4,5,6,7,8
[/TD]
[/TR]
[TR]
[TD]7
[/TD]
[/TR]
[TR]
[TD]2,3,4
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[/TR]
[TR]
[TD]5,6A,6E,7,8
[/TD]
[/TR]
[TR]
[TD]5
[/TD]
[/TR]
</tbody>[/TABLE]

























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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

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