PDA

View Full Version : Solved: assign value to array



benong
10-26-2010, 09:56 PM
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"

Bob Phillips
10-27-2010, 12:23 AM
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.

benong
10-27-2010, 01:08 AM
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

Bob Phillips
10-27-2010, 01:10 AM
I think that is how I would probably do it.