mike760534211
New Member
- Joined
- Sep 25, 2014
- Messages
- 13
I have a sheet that can contain upwards of 1500-2000 rows. I am trying to get VBA to filter based on certain if criteria matches items pull into an array. Part of my code work perfectly since the column (Column U) only have minimal criteia to filer by to begin with.
Column D on the other hand has upwards of 2000 items to filter by based on the month of the report and it too large so i am pulling the data into an array. What i want to do is have column D match only 7 items from the array it created from that column and filter out only those 7 items leaving the remainder, is that possible? any help would be appreciated.
Column D on the other hand has upwards of 2000 items to filter by based on the month of the report and it too large so i am pulling the data into an array. What i want to do is have column D match only 7 items from the array it created from that column and filter out only those 7 items leaving the remainder, is that possible? any help would be appreciated.
Code:
Sub Array_Filter()
Dim i As Long
Dim myArr As Variant
'Pulls Array from column D
myArr = Range("$D$2:$D$2000")
'Filters Column U and works correctly since it has minimal createria to be able to filter by
ActiveSheet.Range("$U$2:$U$2000").AutoFilter Field:=21, Criteria1:=Array( _
"ColumnU item 1", "ColumnU item 2", "ColumnU item 3"), Operator:=xlFilterValues
'Filter Column D where 7 criteria items match array created from Column D in myArr
Sheet3.Range("D2").AutoFilter _
Field:=4, _
Criteria1:=myArr("ColumnD item 1", "ColumnD item 2", "ColumnD item 3", "ColumnD item 4", "ColumnD item 5", "ColumnD item 6", "ColumnD item 7"), _
Operator:=xlFilterValues
End Sub