+ Reply to Thread
Results 1 to 11 of 11

Remove selected item from listbox

  1. #1
    Forum Contributor
    Join Date
    04-27-2006
    Location
    Cayman Islands
    Posts
    379

    Remove selected item from listbox

    Sorry, should be a simple one...

    I can add an item from one list box to another using the following...

    Please Login or Register  to view this content.
    But I want to be able to remove the item from the listbox by clicking it. Tried this but doesn't work!

    Please Login or Register  to view this content.
    Last edited by ChrisMattock; 12-04-2008 at 03:14 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    04-11-2006
    Posts
    407
    I would recommend you use the double-click over single-click since when you remove an item it'll reset the focus to act as if you single-clicked again. Here's my suggestion:
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    04-27-2006
    Location
    Cayman Islands
    Posts
    379
    That's great - thanks for the help, one last thing, would it be possible to remove the item from the original ListBox when it is clicked, so it appears to move from one to the other? Then when it is removed it returns to the original? Thanks again for your help!

  4. #4
    Forum Contributor
    Join Date
    04-27-2006
    Location
    Cayman Islands
    Posts
    379
    No worries have sorted it myself, thanks!

    Please Login or Register  to view this content.

  5. #5
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573
    I would not use the Click event.

    You can not use RowSource when you use RemoveItem of course.

    I would do this:
    Please Login or Register  to view this content.

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434
    I know your solved but you may find this of interest.
    http://www.andypope.info/vba/listboxmover.htm
    Cheers
    Andy
    www.andypope.info

  7. #7
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573
    If you are going to use the same code for 2 or more listbox controls, you might want to use another sub.

    e.g.
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    04-27-2006
    Location
    Cayman Islands
    Posts
    379
    That's brilliant, thank you all so much for your help, I have what I need now! +rep to you all.

  9. #9
    Registered User
    Join Date
    01-21-2012
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Remove selected item from listbox

    I also trying to remove an item from a listbox. It works fine when a select any item except the last one listed.
    When I select the last item to remove all items in the listbox are removed

    here is the code

    Please Login or Register  to view this content.

  10. #10
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Remove selected item from listbox

    prestopr, you should really start your own thread.

    If the Multiselect property is fmMultiSelectSingle then it will delete all items as the highlighed item will automatically become the last item in the list after deletion.
    When not the last item the highlighted item is that of the loop counter so does not get processed again.

    If selectsingle no need to loop.

  11. #11
    Registered User
    Join Date
    01-21-2012
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Remove selected item from listbox

    thanks very much for your help
    and I will start my owon thread next time

    cheers

+ 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