Repopulate UserForm ListBox from CheckBox

  • Re: Repopulate UserForm ListBox from CheckBox


    Hi vmandr


    Looks like you have got yourself in a bit of a muddle. The code looks to me to be overly complex for what you are attempting to do. Lets get rid of your code and start fresh. Basically if I have read your process correctly, you want to concatenate Cols A abd B if Check box 1 is clicked and you want to concatenate Cols B and C if Check box 2 is clicked. This is what your code was telling me anyways. So here is the code. You naturally will need to make the range and array dynamic but this will get you on your way. I attached your workbook to show workings.


    Take care


    Smallman


  • Re: Repopulate UserForm ListBox from CheckBox


    Why not use option buttons, then you won't need code to change the value of one control when the other is clicked?


    Also, why not use a multicolumn listbox?


    Then you could display both columns of data without having to concatenate them.


    If you need the '-' at some point, eg for a search, just add it when it's needed.


    Anyway, here's the code for option buttons.


    PS If you do need the '-' then that can be added quite easily.


    PPS Why are you using End? That will stop all code that's running.

    Boo!:yikes:

  • Re: Repopulate UserForm ListBox from CheckBox


    Here's some sample code to add the '-'.

    Boo!:yikes:

  • Re: Repopulate UserForm ListBox from CheckBox


    Wow !


    Thank you both Smallman and jproffer and Norie (time and code), yes this is what I needed, in the simple form, cause I want to try the same with a multi-column listbox,
    and my problems started when the code met a line "Listbox1.Clear" in my code. So I simplified it as per example posted and tried various combinations, yet the error reappeared.
    Can you please extend courtesy and advise if you had been able to reproduce the error and what was the cause ?
    Smallman
    No need for '-' just a visual clue for me, as for the End, because Excel crashed all the time bypassing the error trap (!?)
    Norie
    I chosen check box cause they cant be pushed / selected unintentionally as with buttons.
    Multicolumn is what I really need but have hard time understanding headers, array, clear the list and get data from different sheets to populate the list.
    I've yet to see a thorough example covering the subject :)


    thanks again

  • Re: Repopulate UserForm ListBox from CheckBox


    Option buttons can't be pushed by accident either.


    Not sure what you meant about headers, arrays etc.


    If you want a header in a listbox you have to use RowSource to populate it from a range.


    You don't have to use an array to populate a listbox either, you can use AddItem or you can use List with a range.


    If you want data from a different sheet add a worksheet reference for the range in the code. For example.


    You might notice Clear isn't used here, it's not needed as List replaces the contents of the listbox not adds to it.

    Boo!:yikes:

  • Re: Repopulate UserForm ListBox from CheckBox


    Another option would be to use a three column ListBox and have the option buttons control which columns are visible.


  • Re: Repopulate UserForm ListBox from CheckBox


    Norie thank you


    "You might notice Clear isn't used here, it's not needed as List replaces the contents of the listbox not adds to it. "
    Sorry was missing this fact, i just thought it will add to list...As for RowSource I have trouble having to define meaningful headers cause the ones on top of
    the worksheets aren't ! also I try to get data from different (non-contiguous) columns combined in a list. I dont know if this has some thing to do with bad worksheet / userform design
    I would appreciate your comment on this. Also I post a modified workbook with cumbersome multicolumn. Cant even get the times right, despite formatting !!


    Mike thank you
    It is a bright idea, I ll give it a shot. Is amazing what this With - End With can do !


    forum.ozgrid.com/index.php?attachment/44904/

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!