VBA - Use array as criteria in autofilter

RCBricker

Well-known Member
Joined
Feb 4, 2003
Messages
1,560
I have this somewhere, but cannot find it AND I cannot seem to see what I am doing wrong here.

I have a select case that assigns values to an array. I then use the array as criteria for an autofilter. The code I have works for assigning the elements to the array, but when the autofilter runs the spreadsheet shows the header row as filtered, but no selections are made in the filter.

Code:
'For Each varI In arrLINE
'Debug.Print varI
'Next


                wsUTBAFS.AutoFilterMode = False
                rngHEAD.AutoFilter Field:=intSGL, Criteria1:=Array(arrLINE)

I have also run the code as such

Code:
'For Each varI In arrLINE
'Debug.Print varI
'Next


                wsUTBAFS.AutoFilterMode = False
                rngHEAD.AutoFilter Field:=intSGL, Criteria1:=arrLINE

The code for assigning the elements of the array

Code:
            arrLINE = Array("510000", "510900", "520000", "520900", "531000", _
                            "531100", "531200", "531300", "531700", "531800", _
                            "531900", "532500", "532900", "540000", "540900", _
                            "590000", "590900", "610000", "619000", "619900", _
                            "631000", "632000", "633000", "634000", "640000", _
                            "650000", "660000", "661000", "671000", "672000", _
                            "673000", "679000", "680000", "685000", "690000", _
                            "711000", "711100", "711200", "718000", "719000", _
                            "721000", "721100", "721200", "728000", "729000", _
                            "729200", "730000", "760000", "850000", "880100", _
                            "880200", "880300", "880400")

Any ideas?

Thanks,
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
try
Code:
rngHEAD.AutoFilter intSGL, arrLINE, xlFilterValues
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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