lundi 20 avril 2015

Using .AddItem With Different Comboboxes in Excel VBA Userform

I have a userform with a lot of comboboxes. I am trying to use .AddItem when the userform is intialized, with no success.

Here is what I have tried so far:

Sub Userform_Initialize()
  Dim cCont As MSForms.ComboBox

  For Each cCont In Me.Controls
    cCont.AddItem "Item Added"
  Next cCont
End Sub

I usually get a runtime error 13 "type mismatch" come up. Not sure if that has anything to do with the button I have on the userform as well.

How do I loop through a userform and use .AddItem to each combobox? Once I get the code on how to do this, I'll wrap it in an If statement to only add it to certain comboboxes with certain words in the name, if that helps for context.

Thanks in advance,

-Anthony

Aucun commentaire:

Enregistrer un commentaire