+ Reply to Thread
Results 1 to 9 of 9

Alphabetizing/sorting an array whats the best way

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Alphabetizing/sorting an array whats the best way

    Hi,

    I have an array of strings. Its an array of file names.

    I have about 376 entries in the array.

    I want to alphabetize the arrary but i am not sure the best way.

    Is the best way
    1)to save the array to a dummy sheet in excel
    2) sort in excel
    3) read into array from excel

    Or is there a better way? Also, if this is the best way can someone point me in the right direction as to how to do this......efficiently.

  2. #2
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: Alphabetizing/sorting an array whats the best way

    does any one know the best way?

    is it faster to put array contents in sheet, then sort, then read contents from sheet back into array or is it faster to sort just the array itself?

    Please let me know?

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Alphabetizing/sorting an array whats the best way

    see: http://www.cpearson.com/excel/QSort.htm

  4. #4
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: Alphabetizing/sorting an array whats the best way

    thanks for the link.

    What i could not find in the link is which way i should go. The link says that if the worksheet is protected then use the qsort..........my worksheet is not protected and i can store stuff to do the sort..........but again it does not address the issue of which one is faster.

  5. #5
    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: Alphabetizing/sorting an array whats the best way

    For a few hundred elements, the time difference would be negligible.

    Greetings, DO, long time no see!
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Forum Expert Colin Legg's Avatar
    Join Date
    03-30-2008
    Location
    UK
    MS-Off Ver
    365
    Posts
    1,256

    Re: Alphabetizing/sorting an array whats the best way

    Personally, I would sort the array purely within VBA. There are lots of different sorting algorithms available; for what you describe I would use a QuickSort algorithm. For an array of this size, it will be extremely fast.
    Hope that helps,

    Colin

    RAD Excel Blog

  7. #7
    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: Alphabetizing/sorting an array whats the best way

    I agree with Colin; I would only ever copy an array to a worksheet to sort a multi-column array by multiple fields.

  8. #8
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: Alphabetizing/sorting an array whats the best way

    ok.....do you have any code for a good quicksort.......i will try it

  9. #9
    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: Alphabetizing/sorting an array whats the best way

    I do, but Saturday is my InsertionSort day:

    Please Login or Register  to view this content.
    The (1D) array is sorted in situ, e.g.,

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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