Variable for userform

AMAS

Active Member
Joined
Apr 11, 2010
Messages
472
I am stuck on this one...

How do I cut this code down by using a variable instead of harding each combobox's numbers (e.g. 1, 2, 3)?

Code:
' Populate options on userform
  MyArray = Array("Apples", "Bananas", "Grapes", "Oranges")
    For Ctr = LBound(MyArray) To UBound(MyArray)
        Fruits.ComboBox1.AddItem MyArray(Ctr)
        Fruits.ComboBox2.AddItem MyArray(Ctr)
        Fruits.ComboBox3.AddItem MyArray(Ctr)
    Next

I wanted to use something like:

Code:
For n = 1 to 3
  Fruits.ComboBox(n).AddItem MyArray(Ctr)
Next n

but its not working. Any thoughts?

Cheers.

AMAS
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
You might have to reference each combobox individually e.g
for each combobox on userform 1 kind of thing
 
Upvote 0
Code:
For n = 1 to 3
  Fruits.Controls("ComboBox" & i).AddItem MyArray(Ctr)
Next n
 
Upvote 0

Forum statistics

Threads
1,224,605
Messages
6,179,860
Members
452,948
Latest member
UsmanAli786

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