PDA

View Full Version : VBA Array Help in filtering data with logic



malleshg24
11-07-2019, 10:07 PM
Hi Team,


I am trying to understand Array here, I can filter data with this array with the below Code.

Dim Myarray As Variant
Myarray = Array("A", "B", "C", "D", "E")
Sheet1.Range("A1").CurrentRegion.AutoFilter 1, Criteria1:=Myarray, Operator:=xlFilterValues


I cant filter data with this below code. if I take array from range

Dim myarray2 As Variant
myarray2 = Sheet2.Range("a1:a5").Value 'It contains (A,B,C,D,E)
Sheet1.Range("A1").CurrentRegion.AutoFilter 1, Criteria1:=myarray2, Operator:=xlFilterValues


Are below array are different? even though same values.
Myarray = Array("A", "B", "C", "D", "E")
myarray2 = Sheet2.Range("a1:a5").Value


please suggest a solution for converting multidimension into single and vice - versa.


Thanks in advance
mg

大灰狼1976
11-08-2019, 12:09 AM
Hi malleshg!
Criteria1 must be a one-dimensional array.
You can modify it as below:

myarray2 = application.transpose(Sheet2.Range("a1:a5").Value)