View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Sorting contents of an array

Here's an example using Quicksort from the archives

Sub QuickSort(SortArray, col, L, R)
'
'Originally Posted by Jim Rech 10/20/98 Excel.Programming
'Modified to sort on first column of a two dimensional array
'Modified to handle a a second dimension greater than 1 (or zero)
Dim i, j, X, Y, mm


i = L
j = R
X = SortArray((L + R) / 2, col)


While (i <= j)
While (SortArray(i, col) < X And i < R)
i = i + 1
Wend
While (X < SortArray(j, col) And j L)
j = j - 1
Wend
If (i <= j) Then
For mm = LBound(SortArray, 2) To UBound(SortArray, 2)
Y = SortArray(i, mm)
SortArray(i, mm) = SortArray(j, mm)
SortArray(j, mm) = Y
Next mm
i = i + 1
j = j - 1
End If
Wend
If (L < j) Then Call QuickSort(SortArray, col, L, j)
If (i < R) Then Call QuickSort(SortArray, col, i, R)
End Sub


Sub Tester1()
Set rng = Range("I7").CurrentRegion
vArr = rng.Value
QuickSort vArr, 5, LBound(vArr, 1), UBound(vArr, 1)
Range("I26").Resize(UBound(vAr*r, 1), UBound(vArr, 2)).Value = vArr
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Craig Wilks" wrote in message
...

Is it possible to sort the contents of an array before loading the
array's contents into a combo box. If so, how is it performed. If not,
then is it possible to sort the contents of the combo box immediately
after loading it is completed?
Thanks for the help.
Craig Wilks

*** Sent via Developersdex http://www.developersdex.com ***