+ Reply to Thread
Results 1 to 9 of 9

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

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Post 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.
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    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.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

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

    Quote Originally Posted by shg View Post
    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. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    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. #5
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

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

    Quote Originally Posted by shg View Post
    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. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    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. #7
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

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

    Quote Originally Posted by shg View Post
    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. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    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.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  9. #9
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

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

    Quote Originally Posted by JosephP View Post
    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!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1