This is my array of arrays:
Code: Select all
myTable = array( _
array("max", "joe", "mel"),_
array("foo", "kid", "jim"),_
array("wil", "ron", "oxo"),_
array("bar", "bob", "don"))Thx
Code: Select all
myTable = array( _
array("max", "joe", "mel"),_
array("foo", "kid", "jim"),_
array("wil", "ron", "oxo"),_
array("bar", "bob", "don"))Code: Select all
Sub testSort
Dim myTable As Variant
myTable = array( _
array("max", "joe", "mel"),_
array("foo", "kid", "jim"),_
array("wil", "ron", "oxo"),_
array("bar", "bob", "don"))
ShowArray(myTable, "Was")
sortByColumn(myTable)
ShowArray(myTable, "At now")
End Sub
Sub sortByColumn(SortList As Variant)
Dim s as Integer
Dim t as Integer
Dim i as Integer
Dim sortvalue1 As Variant
Dim sortvalue2 As Variant
i = Ubound(SortList)
For s = 1 to i
For t = 0 to i-s
sortvalue1 = SortList(t)
sortvalue2 = SortList(t+1)
If CompareArray(sortvalue1, sortvalue2) > 0 Then
SortList(t) = sortvalue2
SortList(t+1) = sortvalue1
End If
Next t
Next s
End Sub
Function CompareArray(a1, a2) As Integer
Dim i&
For i = LBound(a1) To UBound(a1)
If (a1(i) > a2(i)) Then
CompareArray = 1
Exit Function
ElseIf (a1(i) < a2(i)) Then
CompareArray = -1
Exit Function
EndIf
Next i
CompareArray = 0
End Function
Sub ShowArray(LocArray As Variant, Optional sTitle As String)
Dim i As Long
Dim msgstring
msgstring = ""
For i = LBound(LocArray) to Ubound(LocArray)
msgstring = msgstring + Join(LocArray(i),", ") + chr(13)
Next
Msgbox (msgstring, 0, sTitle)
End SubCode: Select all
SortByColumn(myTable, 1)Code: Select all
max joe mel
bar bob don
foo kid jim
wil ron oxo