Hi I've created a little example to illustrate the problem that I'm facing.
Suppose I've the following data:
1 3 2
3 1
5 2
4
2
Now I would like to enter this data into a two-dimensional array. It would be very convenient if the array has as many indexes as elements. In the above data there is 9 elements of data therefore the array should have 9 indexes, if this was a one dimensional array it would be easy: dim array(1 to 9), but the second dimension in a two-dimensional array should illustrate the column.
I've tryed the following but without succes:
[vba]
Option Base 1
Dim x(), O(3) As Integer
Dim i, j As Integer
Sub test()
For i = 1 To 3
For j = 1 To 5
If Cells(i, j) > 0 Then
O(i) = O(i) + 1
ReDim Preserve x(O(i), i)
x(O(i), i) = Cells(i, j)
End If
Next j
Next i
MsgBox ("numbers in column A: " & UBound(x, 1))
End Sub
[/vba]
The problem with the above code is: ReDim Preserve x(O(i), i), but I don't how to fix it. How do I redim my array in this example?
Your help would be appreciated.
Regards
Troels