How to give an array value to different comboboxes in vba excel?

dpa

New Member
Joined
Oct 22, 2011
Messages
14
Hi, I have 4 comboboxes in a formcontrol (excel 2007, vba), each combobox has the name: Combobox_01 Combobox_02 Combobox_03 Combobox_04 I want to give all comboboxes the same array values "A","B","C","D","E","F" How do I do this efficiently?, I tried a For-NEXT loop, but I am not sure how to assign the For value from 1 to 4 to each combobox and it gives me an error...
 
although it doesn't need to be in the click event:
Code:
Private Sub UserForm_Click()
ary = Array("A", "B", "C", "D", "E", "F")
For i = 1 To 4
  Controls("Combobox_" & Format(i, "00")).List = ary
Next i
End Sub

This seems to only work if one is using a userform. I have an activex combobox in a worksheet. This does not work with that. How would the coding change to work with an activex combobox embedded in a worksheet?
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
You would need to refer to the OLEObjects collection:
Code:
Me.OLEObjects("Combobox_" & Format(i, "00")).Object.List = ary

If the code is not in the same worksheet, use the relevant sheet rather than 'Me'.
 
Upvote 0
Please post all of your code and state where the code is located - i.e. which module - and which line causes the error.
 
Upvote 0
Nevermind. It was the Format(I, "00").

It was making the combobox name "ComboBox01" and my boxes were named "ComboBox1"

Thank you for the help!
 
Upvote 0

Forum statistics

Threads
1,216,084
Messages
6,128,728
Members
449,465
Latest member
TAKLAM

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top