Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Array Sorting in VB
Is there a VB function to sort an array? Something like:
AA(0) = 3 AA(1) = 6 AA(2) = 0 Call ArraySort(AA) Result: AA(0) = 0 AA(1) = 3 AA(2) = 6 I can write my array to cells and uses Range.Sort, or write my own ArraySort routein; but is there any way more efficient than this? Tx, Randall |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Array Sorting in VB
Randall
one way: Sub BubbleSort(List() As String) '' Sorts the List array in ascending order Dim First As Integer, Last As Integer Dim i As Integer, j As Integer Dim Temp First = LBound(List) Last = UBound(List) For i = First To Last - 1 For j = i + 1 To Last If UCase(List(i)) UCase(List(j)) Then Temp = List(j) List(j) = List(i) List(i) = Temp End If Next j Next i End Sub This is from a routine to sort worksheet names - found on the xl-logic.com site. I seem to recall one of the MVPs had examples of sorting single and two dimensional arrays ... but off the top of my head I can't think where they are. Regards Trevor "Randall" wrote in message ... Is there a VB function to sort an array? Something like: AA(0) = 3 AA(1) = 6 AA(2) = 0 Call ArraySort(AA) Result: AA(0) = 0 AA(1) = 3 AA(2) = 6 I can write my array to cells and uses Range.Sort, or write my own ArraySort routein; but is there any way more efficient than this? Tx, Randall |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
sorting array formula | Excel Worksheet Functions | |||
Sorting within an array | Excel Discussion (Misc queries) | |||
Sorting 2D portion of 5D Array | Excel Programming | |||
Sorting 2D Array | Excel Programming | |||
Sorting Names in an Array | Excel Programming |