ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sorting Unions (https://www.excelbanter.com/excel-programming/276045-sorting-unions.html)

Alex[_9_]

Sorting Unions
 
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

Dave Ring

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.




All times are GMT +1. The time now is 05:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com