Consulting

Results 1 to 4 of 4

Thread: Solved: assign value to array

  1. #1

    Solved: assign value to array

    hi,
    After filtering data, how can i assign these filtered data (visible cell) to an array?
        Worksheets("Sheet1").Range("H1").AutoFilter
        Selection.AutoFilter Field:=2, Criteria1:="none"

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I don't think you can automatically do this. The visible range will consist of many range areas, and if you set an array to this range it will only pick up the first area.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    dear xld,

    many thanks for your advice.
    Now i know why i kept getting error messages for the whole day.
    I adopt another method which is now working for me
            For i = 2 To RowCount
                If Cells(i, 8).Value = "none" Then
                    arraySize = arraySize + 1
                End If
            Next i
            ReDim myArray(arraySize - 1) As Variant
            n = 0
            For i = 2 To RowCount
                If Cells(i, 8).Value = "none" Then
                    myArray(n) = Cells(i, 6).Value
                    n = n + 1
                End If
            Next i
            FilteredData = myArray

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I think that is how I would probably do it.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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