Thread: Sorting Unions
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Ring Dave Ring is offline
external usenet poster
 
Posts: 20
Default Sorting Unions

Bubble sort may work if Alex's lists are as short as those in his
example, but is one of the slowest sorts known. Sorting 6400 random
strings in Excel 2001 VBA on an 800 mhz Powerbook:

Bubble 164 sec; stable
Selection 61 sec; stable
Insertion 33 sec; stable

Comb 0.62 sec
Shell 0.54 sec

Heap 0.52 sec
Merge 0.38 sec; stable
Quick 0.24 sec

Radix 0.20 sec; stable

The only virtues of bubble sort are that it's simple and sorts stably,
but the same is true of insertion sort, which is five times faster:

Sub InsertionSort(A())
Dim LO&, HI&, I&, J&, V

LO = LBound(A): HI = UBound(A)
For I = LO + 1 To HI
V = A(I)
For J = I To LO + 1 Step -1
If V < A(J - 1) Then A(J) = A(J - 1) Else Exit For
Next J
A(J) = V
Next I
End Sub

This assumes values from both ranges have been read into array A().

Dave Ring

Tom Ogilvy wrote:
No, this isn't supported.

You could do a bubble sort and manage the data yourself.

See John Walkenbach's site for a sample bubble sort.

http://j-walk.com/ss/excel/tips/tip47.htm
How to fill a listbox with unique items

there is code to do a bubble sort toward the bottom of the code on that
page.

Here are some code samples for a selection sort and a bubble sort
http://support.microsoft.com/?id=133135
XL: Using a Visual Basic Macro to Sort Arrays in Microsoft Excel

You would have to adapt them to handle the additional column/row.