+ Reply to Thread
Results 1 to 4 of 4

Userform: Double click to remove selected removes all items.

  1. #1
    Registered User
    Join Date
    03-25-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    10

    Userform: Double click to remove selected removes all items.

    Hi All,

    I have a userform where after a listbox is populated the user can double-click on an item to remove it from the list. Most of the time this works as desired. However, when the user double-clicks on a blank space or on the last item in the list all items are removed. Below is my code for the double-click event. Does anybody have a modification to the code so that it will not remove all items when the last item, or a blank, is double-clicked?

    Please Login or Register  to view this content.
    Thanks in advance!




    --------------------------------------------
    Insightful tag-line here.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Userform: Double click to remove selected removes all items.

    I don't know what's going on with your blank items, without knowing more about how you load the list. But this will fix your "last item" problem.

    Please Login or Register  to view this content.
    If your listbox has MultiSelect set to single, no need for a loop--you can do this

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Userform: Double click to remove selected removes all items.

    By the way, when the list is set to Single, if you delete the selected item VBA will cause another item to be selected. If your selected item is the last item and you delete it, then VBA will select the now-last item. That's why your loop deletes every item when you double-click the last one. If the item is not the last one, then the item in the same position in the list will be selected.

  4. #4
    Registered User
    Join Date
    03-25-2014
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Userform: Double click to remove selected removes all items.

    6StringJazzer,
    Thanks for the solution! That worked perfectly. When blank is clicked it defaults to selecting the last item, so both issues were generated by the same root cause. Again, Thanks!

+ 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. Double Click Text Box on a UserForm to Look-up Value in Another Tab
    By timtomm66 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-23-2013, 06:33 AM
  2. Double Click to add/remove Tick
    By smuzoen in forum Excel Tips
    Replies: 25
    Last Post: 07-27-2012, 01:50 PM
  3. List box Double Click Copy and remove item
    By thameem127 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-18-2012, 05:00 PM
  4. userform label double-click goes to click event
    By John Paul Fullerton in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-19-2006, 01:00 PM
  5. [SOLVED] Need selected item from listbox after double click
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-23-2006, 11:20 AM

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