+ Reply to Thread
Results 1 to 8 of 8

Deselect items in list box on userform

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

    Deselect items in list box on userform

    hi,

    I have a macro where I show a userform to the user. On this userform i have 3 listboxes. For the purposes of this question i will really only reference listbox1. I have created a "test macro" showing my problemm / question.

    Basically, the user selects an entry in listbox1 .........using the listbox1_click sub-procedure i "do certain things". If i detect an error then i prompt the user to select another entry in listbox1.

    My problem is that when i detect an error and i try to DESELECT the entry that was selected by the user in listbox1 .......i cant. In fact when the user selects an item in listbox1 and an error is detected my msgbox prompt is shown 2 times (dont know why) and the item selected in listbox1 is NOT DESELeCTED.

    Any ideas?

    If you have any questions please let me know.
    Attached Files Attached Files

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

    Re: Deselect items in list box on userform

    In your Listbox click event after you show your error message you using
    Please Login or Register  to view this content.
    This will fire the click event again. Try just using Exit For after displaying your message
    Thanks,
    Mike

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

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

    Re: Deselect items in list box on userform

    hi mike7952 ,

    that gets rid of showing the dialog box twice but what about deselecting the selected item in listbox1? how to do this?

    thanks again! that showing of the listbox twice was giving me a headache!

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

    Re: Deselect items in list box on userform

    thanks to a previous post i am now able to get rid of the msgbox displaying twice

    However, after the msgbox disappears the first time the listbox1 item is still selected "highlighted" blue.

    is there a way to like "reset" listbox1 so none of the items are highlighted or selected.

    i am enclosing the file/macro
    Attached Files Attached Files

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

    Re: Deselect items in list box on userform

    One way is after the for next statement in your Listbox click event is to clear the listbox and reload it

    Please Login or Register  to view this content.

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

    Re: Deselect items in list box on userform

    thanks. that looks like it might work. i guess there is no "easy" way to do it

    thanks again.

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

    Re: Deselect items in list box on userform

    well, i thought that might work. i tried it but for some reason its not working.

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

    Re: Deselect items in list box on userform

    got it to work.

    In my test macro that i put here......it worked by just exiting the for-loop but in my "real" program apparently i had to "exit sub" to get it to work. get it to work was done by clearing and then re-populating the listbox.

+ 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