CheckBox Checked if Listbox column 5 text matches checkBox text?

  • Hi,
    I have a UserForm with 39 checkBoxes that relate to different assessments that employees may need.

    I have a ListBox that imports the assessments currently held by the operative from the worksheet.

    The assessments are in column 5 of the ListBox.

    The name of the assessment matches the caption name of the CheckBoxes.

    is there a way of writing code to automatically checking the CheckBoxes if the caption matches the assessment listed in column 5 of the ListBox?

    Any help will be much appreciated.


  • Sure. Iterate through the the listbox rows and use something like Me.Controls(listbox.ListIndex(n,4)) = True. With that many controls, a better way would be to use object oriented programming by creating a class for the CheckBoxes, but that's a more advanced topic.

  • Hi Jonathan,

    I'm stuck on how to code the checkboxes to check the box, if your code above matches the checkbox caption value?

    I'm still fairly new to VBA.


  • Sorry, I thought the listbox column contained the names of the checkboxes, but upon rereading your first post I see that it instead has the checkboxes' captions. That means you'll have to iterate though both the listbox rows and the checkboxes (to compare to their Caption properties). Does that give you enough to figure this out or would you like some sample code? (Another, more elegant, approach would be to create a scripting dictionary to hold the checkbox objects using their captions as the keys; does that make sense to you?)

    If you know OOP from another language, please be aware that VBA does have limited support for OOP and will allow you to create a class and instantiate a class object for each checkbox. If you don't know another OOP language, then ignore this paragraph for now. ;)

  • Here's an example for the first method, which should be the easiest to understand. I don't know what event repopulates your listbox, but this code should be for that:

  • Berikut adalah contoh metode pertama , yang semestinya paling mudah dipahami. Saya tidak tahu acara apa yang mengisi kembali kotak daftar Anda, tetapi kode ini harus untuk itu:

    hi JonathanVH, hi Andyw111, from the above question, my case is almost the same as the Andyw111 question above, but somehow the code that is shared doesn't work when I try the macro script.

    I don't know maybe because it's a different case.

    please help, any help I will really appreciate.

    for consideration I attach a screenshot of my work project


  • Welcome to the Forum

    Please start your own post. Posting in another member's Thread is known as hijacking and is not allowed here. By all means add a link to a Thread that may be related to your question.

Participate now!

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