Sorting Unions

  • Thread starter Thread starter Alex
  • Start date Start date
A

Alex

I am trying to find a way of sorting 2 disconnected Ranges
i.e A1:L1 and A3:L3.
Can i make a Union of the 2 ranges and then sort them?
I tried and couldn't.
Thanks in advance,
Alex
 
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
 
Back
Top