0

i ran in to this little problem while working with Userforms in Excel.

I have a list of comboboxes, that all need to have in the same data, day and month.

Sub Userform_Initialize()
Dim arr(31) As Variant
Dim arr2(12) As Variant
Dim i As Integer
For i = 1 To 31
    arr(i) = i
Next
ComboBox1.list = arr()

For i = 1 To 12
    arr2(i) = i
Next
ComboBox2.list = arr2()
End Sub

That all works fine. BUT, i would like for the code to then be repeated for all my combo boxes that i have. Lets just say they are called ComboBox1 .. Combobox10. I have tried the following, without it working, but i don't have a great understanding of how these pieces work in VBA.

Dim Comboboxes(10) as Variant / Object / String (I have tried all)
Comboboxes(1) = Combobox1 / "Combobox1" (I have tried both)
...
Comboboxes(10) = Combobox10

For i = 1 To 31
    arr(i) = i
Next
Comboboxes(1).list = arr()

Obviously i would also have to set up an i loop for the comboboxes, but it does not work. Is it just not possible or what am i doing wrong?

Hudlommen
  • 89
  • 1
  • 11
  • 2
    `As Object`, and it's [`Set Comboboxes(1) = Combobox1`](http://stackoverflow.com/a/20763733/11683). Otherwise you're good. – GSerg Apr 28 '16 at 14:15
  • This place on the interwebs is such a beautiful place. Thank you so much! – Hudlommen Apr 28 '16 at 14:22
  • i didn't understand if `Comboboxes` is an Array pointing to combobox'es or to the data in the combobox'es (wich would be an array of arrays in the second case). – Patrick Lepelletier Apr 29 '16 at 08:27

0 Answers0