+ Reply to Thread
Results 1 to 12 of 12

Sort Array Alphabetically

  1. #1
    Registered User
    Join Date
    05-23-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    79

    Exclamation Sort Array Alphabetically

    Hello,

    I am successfully able to sort through a range of cells and allocate names to various arrays based on specified criteria. Those arrays are then used to populate listboxes in a userform.

    I am stuck on how to sort the array alphabetically before populating the listbox with the names.

    Any help would be great...please see bottom of code below for populating listbox section

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Sort Array Alphabetically

    why not sort on sheet, then put in array ?
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    05-23-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Sort Array Alphabetically

    I figured that was also an option, but I thought it may be easier to do it directly in vb...can you please recommend the code for that process?

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Sort Array Alphabetically


  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Sort Array Alphabetically

    Hello gsurge,

    This macro will sort a list in either ascending (A-Z) or descending (Z-A) order. The default is ascending. The list can be either 1-D or 2-D single column.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  6. #6
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Sort Array Alphabetically

    try this

    Please Login or Register  to view this content.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  7. #7
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Sort Array Alphabetically

    as an option
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    05-23-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Sort Array Alphabetically

    Thanks Leith. I placed your code in a module and called it using:

    Please Login or Register  to view this content.
    But this didn't sort the array...did I miss a step?

  9. #9
    Registered User
    Join Date
    05-23-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Sort Array Alphabetically

    Nilem,

    That worked perfectly! Thank you so much!

    One quick thing...I still have a space at the beginning of my array...apparently I didn't remove it. Any idea on how to get rid of this?

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Sort Array Alphabetically

    Hello gsurge,

    The macro is a Function that returns the original array as a sorted array.
    Please Login or Register  to view this content.

  11. #11
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Sort Array Alphabetically

    Quote Originally Posted by gsurge View Post
    ...I still have a space at the beginning of my array...
    change this line
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    05-23-2011
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    79

    Re: Sort Array Alphabetically

    thank you again. everything works perfectly.

+ 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