Userform Listbox list combined with Cell Value to display Checkbox as Selected

  • Hi,

    What I'm trying to achieve is to load a complete list (from a named range "koetswerk") and compare it with the values of an active cell (in row K) after clicking in it. If the values (Ex: SD, P, SUV) are equal to the ones in the complete list, then it should show a "checked" checkbox in Listbox_KW. The listbox can have multiple selections. What I've already found out is how to put the data in the active cell with the Sub cmdADD_Click().

    This is what I know is working:

    'Me.ListBox_KW.List = rngKWA.Value              '<--- LIST ALL FROM NAMED RANGE
    '.List = Split(CStr(ActiveCell.Value), ",")     '<--- LIST SPLITTED CELL VALUES

    I've started out with a For loop. How can the data be compared and .selected ?

    I'm a vba newbie and I'm struggling for days to find a solution that really works (searched many forums) for this. Thank you when responding.

    [ATTACH=JSON]{"alt":"Column K - List All","data-align":"none","data-attachmentid":"1198591","data-size":"custom","height":"367","title":"Koetswerk - Column K - List All.JPG","width":"300"}[/ATTACH]


  • Can you add a sample workbook. This way we don't have to remake the userform.

  • I think this is what you want.

    1. Update this section of your form initialize event.

    2. To get this I googled this string "+vba +select multiple items in listbox" and found examples of how to get it done.

    Also I realize you're new so here's a critique of some of your code.

    1. Good that you're set option explicit ( all variables need to be declared )
    2. Good that you're using error catching ( I still don't )
    3. In your form you referenced the form itself by both frmKW and Me .... to be consistent pick a style stick with it.
    4. You used With / End With which is good. But in your initialize event you NESTED 1 inside the other and both were referencing the listbox.
    5. Use consistent indenting. It will make your code easier to read and follow.

    Other than that .... good job.

Participate now!

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