Wonder if this would help:
Code:
Public Sub BubbleSort(ToSort As Variant, Optional SortAscending As Boolean = True)
' Chris Rae's VBA Code Archive - http://chrisrae.com/vba
' By Chris Rae, 19/5/99. My thanks to
' Will Rickards and Roemer Lievaart
' for some fixes.
'modified by Vlad Cucinschi on May 12 , 2004 to sort a three dimensional array
Dim AnyChanges As Boolean
Dim BubbleSort As Long
Dim Swap1D As Variant, Swap2D As Variant, Swap3D As Variant
Do
AnyChanges = False
For BubbleSort = LBound(ToSort, 2) To UBound(ToSort, 2) - 1
If (ToSort(0, BubbleSort) > ToSort(0, BubbleSort + 1) And SortAscending) _
Or (ToSort(0, BubbleSort) < ToSort(0, BubbleSort + 1) And Not SortAscending) Then
' These two need to be swapped
Swap1D = ToSort(0, BubbleSort)
Swap2D = ToSort(1, BubbleSort)
Swap3D = ToSort(2, BubbleSort)
ToSort(0, BubbleSort) = ToSort(0, BubbleSort + 1)
ToSort(1, BubbleSort) = ToSort(1, BubbleSort + 1)
ToSort(2, BubbleSort) = ToSort(2, BubbleSort + 1)
ToSort(0, BubbleSort + 1) = Swap1D
ToSort(1, BubbleSort + 1) = Swap2D
ToSort(2, BubbleSort + 1) = Swap3D
AnyChanges = True
End If
Next BubbleSort
Loop Until Not AnyChanges
End Sub
Cheers,
Vlad