+ Reply to Thread
Results 1 to 8 of 8

Sort an Array of items by Alpha

  1. #1
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    Fl
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    951

    Sort an Array of items by Alpha

    Hi,

    I have the following script that collects my data into an array and adds to a combo-box, However the data is unsorted. I found a script that is suppose to sort the array, However I'm not having any luck with it. it may be the way I am calling it or something else I cant see at the moment.

    I'm looking to either sort the array then add the items to the combo-box or Just sort the items that are placed in the combo-box. Or maybe someone has another Idea...

    Can someone please take a look and advise.

    Thanks as always, Mike

    Please Login or Register  to view this content.
    The Sort Script...

    Please Login or Register  to view this content.
    Last edited by realniceguy5000; 07-05-2011 at 01:07 PM.

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Sort an Array of items by Alpha

    Please Login or Register  to view this content.



  3. #3
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Sort an Array of items by Alpha

    Don't know if this is any use to you but it's something I use that's similar to what you are trying to achieve but using a collection rather than an array which has the advantage of only accepting unique items as well:

    Please Login or Register  to view this content.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Sort an Array of items by Alpha

    or:

    Please Login or Register  to view this content.

  5. #5
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    Fl
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    951

    Re: Sort an Array of items by Alpha

    Ok, I gave both ways a try,

    @ snb, I was not able to get your codes to work in my situation again I ran into the same problems I did with my sort script. I'm sure it's my fault as I just dont understand what it going on. As you say avoid code you dont understand... just my luck I guess. But thank you for your time...

    @ Dom, I was able to get your option to work, Seems to work better anyway rather than to use an array of items. as I can sort then place the list right away.
    Thank You for your time...

    Mike,
    Thank You, Mike

    Some Helpful Hints:

    1. New members please read & follow the Forum Rules
    2. Use Code Tags...Place[code]Before the first line and[/code] After the last line.
    3. If you are pleased with a solution mark your post SOLVED.
    4. Thank those who have help you by clicking the scales at the top right of the post.

    Here...

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Sort an Array of items by Alpha

    @RNG

    I can't believe you did anything wrong
    Please do what you would ask any OP: post your example workbook.

    cfr. the attachment
    Attached Files Attached Files
    Last edited by snb; 07-05-2011 at 04:21 PM.

  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: Sort an Array of items by Alpha

    Mike,

    Here's a 'black box' approach with an example. It does a simple insertion sort.

    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  8. #8
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    Fl
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    951

    Re: Sort an Array of items by Alpha

    Thanks Shg...Nice Approach...

    @ SNB....Thanks for the lesson.
    I never said your code didn't work in fact you must be a master at taking 100 line scripts and making them 10 or less... lol I just dont understand your logic at times, which makes them harder for me to re-code if needed.
    Maybe one day...

    Thank You, Mike

+ 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