+ Reply to Thread
Results 1 to 12 of 12

How to keep items in ListBox in alphabetical order when removing and adding items to box

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

    How to keep items in ListBox in alphabetical order when removing and adding items to box

    Hi,

    I have a two listboxes on a user form.
    One listbox (A) is an alphabetical list of names. Another listbox (B) contains those name the user selected from listboxA.

    Once the user selects an item in listboxA that item is removed from listboxA and moved to listboxB. However, if user selects name in listboxB and wants to put this name back into listboxA i need it put back into alphabetical order..........any ideas how to do this?

  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: How to keep items in ListBox in alphabetical order when removing and adding items to b

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

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

    Re: How to keep items in ListBox in alphabetical order when removing and adding items to b

    hi, i found some code online before i saw your post......it works "some of the time" i am enclosing the file so you can see what i am doing.

    i cant seem to repeat the error .........any idea why this is not working

  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: How to keep items in ListBox in alphabetical order when removing and adding items to b

    Did you try the code I posted?

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

    Re: How to keep items in ListBox in alphabetical order when removing and adding items to b

    no i did not .........i was trying to figure out the code i was working on as it seemed to be almost right. i will keep trying for alittle longer my code to figure out error then i will try yours.........thanks.

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

    Re: How to keep items in ListBox in alphabetical order when removing and adding items to b

    quick question...........about my code........

    for some reason when i compare a string to another string.......example: string1 = "de something" and string2 = "Zsomething"
    its saying that the "de something" is greater than the "Zsomething" which does not make sense.....

    any idea what is going on?

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

    Re: How to keep items in ListBox in alphabetical order when removing and adding items to b

    fyi:

    string1 = "de krom"
    string2 = "Zack,Jobin L"

    my code when it runs says string1 is > than string2

    it shouldnt be should it?

  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: How to keep items in ListBox in alphabetical order when removing and adding items to b

    String comparison in VBA is case-sensitive by default.

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

    Re: How to keep items in ListBox in alphabetical order when removing and adding items to b

    so "d" is greater than "Z"......huh, did not know this

    so should i convert everything to either upper case or lower case or should i use the strcomp function

  10. #10
    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: How to keep items in ListBox in alphabetical order when removing and adding items to b

    Roger. You could also use Option Compare Text, but I wouldn't recommend it.

  11. #11
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: How to keep items in ListBox in alphabetical order when removing and adding items to b

    If the ListBox is already sorted, this routine will add text and maintain the sort.

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

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

    Re: How to keep items in ListBox in alphabetical order when removing and adding items to b

    thanks you all.

    here is what i ended up with. again i had found some code online and started with that before i saw anyones post here. I just replaced one line of code with a StrComp and it seems to work. thanks again. Took me a while to figure out why it was not working.......but learned something again. thanks.

    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)

Similar Threads

  1. How do I place items in alphabetical order in a column and keep da
    By Angela33 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 PM
  2. How do I place items in alphabetical order in a column and keep da
    By Angela33 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 11:05 AM
  3. [SOLVED] How do I place items in alphabetical order in a column and keep da
    By RagDyer in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-06-2005, 06:05 AM
  4. [SOLVED] How do I place items in alphabetical order in a column and keep da
    By Angela33 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 AM
  5. [SOLVED] How do I place items in alphabetical order in a column and keep da
    By Angela33 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10:05 PM

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