I need to use a string of data for an autofilter field. In the actual macro the creation of the string is more complicated and variable, but the below example recreates my problem more simply.
When I try to use a string variable into the autofilter, the autofilter hides everything. When I use the same string but put it into the Array directly it works. Can anyone help me with how to filter using an Array?
Term = """" & APR & """" & "," & """" & MAY & """"
Debug.Print Term 'just to verify the strings are the same
Arr1 = Array("APR", "MAY") 'works in the filter
Arr1 = Array(Term) 'fails in the filter
Worksheets("Filter").Range("$A:$H").AutoFilter Field:=2, _
Criteria1:=Arr1, Operator:=xlFilterValues
Try this
Dim APR As String
Dim MAY As String
Dim arr1(0 To 1) As String
APR = "APR"
MAY = "MAY"
arr1(0) = APR
arr1(1) = MAY
Worksheets("Filter").Range("$A:$H").AutoFilter Field:=2, _
Criteria1:=arr1, Operator:=xlFilterValues
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.