Are the values in column A numbers? When using a variant array as the Criteria1 with xlFilterValues, numbers must be treated as text so use ary(i) = CStr(.Cells(i, 1).Value2)
to build your array.
Dim ary As Variant
With Worksheets("sheet1").Cells(1, 1).CurrentRegion
'with true numbers in column A this DOES NOT work
ary = Array(1, 2, 3)
.AutoFilter field:=1, Criteria1:=ary, Operator:=xlFilterValues
'with true numbers in column A this DOES work
ary = Array("1", "2", "3")
.AutoFilter field:=1, Criteria1:=ary, Operator:=xlFilterValues
End With
Yes, this seems counter-intuative but that is how to filter for numbers using an array with xlFilterValues. Dates can present a similar issue.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…