Consulting

Results 1 to 2 of 2

Thread: VBA Array Help in filtering data with logic

  1. #1
    Banned VBAX Contributor
    Joined
    Aug 2017
    Posts
    144
    Location

    VBA Array Help in filtering data with logic

    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

  2. #2
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    Hi malleshg!
    Criteria1 must be a one-dimensional array.
    You can modify it as below:
    myarray2 = application.transpose(Sheet2.Range("a1:a5").Value)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •