+ Reply to Thread
Results 1 to 8 of 8

Need to alphabetically sort listbox.

  1. #1
    Registered User
    Join Date
    02-16-2018
    Location
    WI
    MS-Off Ver
    2016
    Posts
    56

    Need to alphabetically sort listbox.

    I have a list box which draws from a sheet which by request of the user must be sorted by part numbers.

    As a result, the mold numbers are not in alphabetical order.

    If I sort by mold number, then naturally the part numbers will not be in order in my second list, which is populated with all part numbers that match the mold number selected in the mold list box.

    So I need something which will pull all the mold numbers from an unsorted column, exclude duplicates, and then display in alphabetical order.



    Currently I am using this, which I got from one of you helpful folks:

    Please Login or Register  to view this content.

    This works perfectly well, aside from the lack of sorting.

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Need to alphabetically sort listbox.

    You can BubbleSort a Dictionary or use a System.Collection.ArrayList instead which has a Sort Command.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  3. #3
    Registered User
    Join Date
    02-16-2018
    Location
    WI
    MS-Off Ver
    2016
    Posts
    56

    Re: Need to alphabetically sort listbox.

    Quote Originally Posted by bakerman2 View Post
    You can BubbleSort a Dictionary or use a System.Collection.ArrayList instead which has a Sort Command.
    Thanks, but to be blunt: I have no idea how to do such a thing.

  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: Need to alphabetically sort listbox.

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

  5. #5
    Registered User
    Join Date
    02-16-2018
    Location
    WI
    MS-Off Ver
    2016
    Posts
    56

    Re: Need to alphabetically sort listbox.

    If I am reading this correctly, this assume the combobox is on a worksheet. I guess I should have clarified that this is within a userform.

    I imagine instead of sub demo() this then would be in the userform_initialize sub with the function placed elsewhere in the code sheet, and then I would have to change it simply to "combobox1.list" instead of "sheet1.combobox1.list" and set the range appropriately (I have a dynamic range set up for this)?

    A lot of this stuff is new to me yet.


    Quote Originally Posted by shg View Post
    Please Login or Register  to view this content.

  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: Need to alphabetically sort listbox.

    The control can be on a userform.

  7. #7
    Registered User
    Join Date
    02-16-2018
    Location
    WI
    MS-Off Ver
    2016
    Posts
    56

    Re: Need to alphabetically sort listbox.

    So that seems to work for sorting but does not exclude duplicates.

    EDIT: I figured it out. I needed to use your code in addition to the existing stuff which sorts out the duplicates.

    I ran what I had, then placed "SortTheBox MoldListbox" afterwards and it works perfectly.

    Thank you!
    Last edited by IMM Tech; 04-24-2018 at 12:56 PM.

  8. #8
    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: Need to alphabetically sort listbox.

    You're welcome.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Sort selected userform listbox items alphabetically
    By kosherboy in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-20-2016, 12:15 AM
  2. How to sort Alphabetically
    By sunblue in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-24-2015, 06:09 AM
  3. Sort Alphabetically
    By Bob@Sun in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 08-23-2015, 10:18 AM
  4. Sort Alphabetically each 6th row
    By Jonathan78 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-17-2013, 03:15 PM
  5. How to sort a listbox alphabetically?...
    By 10121730 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-01-2012, 03:03 AM
  6. sort alphabetically and numerically, then sort rows
    By luke20allen in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-01-2008, 07:00 AM
  7. Listbox to be Alphabetically sorted
    By coreytroy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-19-2007, 07:07 AM

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