djamieson18
New Member
- Joined
- Feb 4, 2012
- Messages
- 8
Hi All,
I have a 2D array where the first colum has a range of dates and the second colum has a range of numbers. I wish to reorder this array in time order. My attempts all seem to fail.
Does anyone know of a way of doing so?
Thanks
Dave
I have a 2D array where the first colum has a range of dates and the second colum has a range of numbers. I wish to reorder this array in time order. My attempts all seem to fail.
Does anyone know of a way of doing so?
Code:
Dim a As Date
Dim b As Date
Dim c As Date
Dim d As Date
a = "01/01/2012"
b = "31/01/2012"
c = "14/04/2012"
d = "31/03/2012"
Dim ArrayXY(3, 1)
ArrayXY(0, 0) = a
ArrayXY(1, 0) = b
ArrayXY(2, 0) = c
ArrayXY(3, 0) = d
ArrayXY(0, 1) = 5
ArrayXY(1, 1) = 6
ArrayXY(2, 1) = 8
ArrayXY(3, 1) = 7
For i = First To Last - 1
For j = i + 1 To Last
If ArrayB(i, 1) > ArrayB(j, 1) Then
For k = FirstCol To LastCol
lTemp = ArrayB(j, k)
ArrayB(j, k) = ArrayB(i, k)
ArrayB(i, k) = lTemp
Next k
End If
strng = ""
For z = LBound(ArrayB, 1) To UBound(ArrayB, 1)
strng = strng & vbNewLine & ArrayB(z, 0)
Next z
MsgBox strng
Next j
Next i
Thanks
Dave