# New to arrays-BubbleSort code(Working)-How do I edit to sort by 2nd column then 3rd?

1. ## New to arrays-BubbleSort code(Working)-How do I edit to sort by 2nd column then 3rd?

I have been using the following code to bubble sort a 2 column 2D array. And it works.

I now want to alter the code to:
1. accept any number of columns in the input array (not limited to 2 columns)
2. allow bubble sorting of two columns (where the column no.s are set when calling the function)

How do I do this?

``Please Login or Register  to view this content.``

2. ## Re: New to arrays-BubbleSort code(Working)-How do I edit to sort by 2nd column then 3rd?

Bubble sort is used as an example of one way to code a sort algorithm, only because it's so intuitive. It's not recommended for any purpose, because it's very slow.

It would be faster to copy the array to a worksheet, sort, and then copy the result.

3. ## Re: New to arrays-BubbleSort code(Working)-How do I edit to sort by 2nd column then 3rd?

Originally Posted by shg
Bubble sort is used as an example of one way to code a sort algorithm, only because it's so intuitive. It's not recommended for any purpose, because it's very slow.

It would be faster to copy the array to a worksheet, sort, and then copy the result.
Thanks for your suggestion shg. I am aware of the potential overhead of BubbleSort. However if the array contains 500 elements or less, BubbleSort is actually faster than sorting an Excel worksheet! (And the arrays I plan to use this on would be a lot smaller than 500).

4. ## Re: New to arrays-BubbleSort code(Working)-How do I edit to sort by 2nd column then 3rd?

If it's less than 500 elements, how much time are you saving?

Or is this another exercise?

5. ## Re: New to arrays-BubbleSort code(Working)-How do I edit to sort by 2nd column then 3rd?

Originally Posted by shg
If it's less than 500 elements, how much time are you saving?
I haven't measured it because the question wasn't about improving the speed (FYI the 500 elements speed I took from John Walkenbachs "Excel 2010 Power Programming").

The question is asking how to edit the code I have posted so that I can Bubble Sort by column 2 and then column 3?

(Don't get me wrong. Your pursuit of speed is an admirable goal but I happen to need this Bubble Sort).

6. ## Re: New to arrays-BubbleSort code(Working)-How do I edit to sort by 2nd column then 3rd?

If you need the result, then you could do as I suggested. If you need a bubble sort, I'll leave you in someone else's capable hands.

Bon soir.

7. ## Re: New to arrays-BubbleSort code(Working)-How do I edit to sort by 2nd column then 3rd?

Originally Posted by shg
If you need the result, then you could do as I suggested.
Because of a number of factors (can't explain here without derailing the thread), I can not use Excel sort on the original range that the array is created on. Which is why I'm asking for multi-column Bubble Sort. Thank you for your suggestions though.

8. ## Re: New to arrays-BubbleSort code(Working)-How do I edit to sort by 2nd column then 3rd?

untested but I reckon it's only a small change
``Please Login or Register  to view this content.``

9. ## Re: New to arrays-BubbleSort code(Working)-How do I edit to sort by 2nd column then 3rd?

Originally Posted by JosephP
untested but I reckon it's only a small change
:D Ladies & Gentlemen - he's done it again! (And he didn't even have to test it first. Yowza!

There are currently 1 users browsing this thread. (0 members and 1 guests)