![]() |
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 |
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 |
All times are GMT +1. The time now is 05:18 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com