Putting data into combo boxes - is there a quicker way than this?

Glove303

Board Regular
Joined
Dec 18, 2010
Messages
65
I tend to populate combo boxes with loops, which I know can be inefficient.

An example would be this:

For X = 1 To 31
Me.Example_Combo.AddItem Format(X, "00")
Next X

I also add ranges from a worksheet, such as:

For X = 3 To LastRow
Me.Example_Combo.AddItem Data.Cells(X, 1).Value
Next X


I have a feeling I could use arrays to speed things up, but I have searched and cannot find a good answer. Can anyone help me on this please?

Many thanks,
James.
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
You can for example replace this:
Code:
For X = 3 To LastRow
Me.Example_Combo.AddItem Data.Cells(X, 1).Value
Next X
with this:
Code:
Me.Example_Combo.List = Range("A3:A" & lastrow).Value
 
Upvote 0
Or for your first example, something like:
Code:
   Me.ComboBox1.List = Array("01", "02", "03", "04") ' etc!
   ' or:
   Me.ComboBox1.List = [INDEX(TEXT(ROW(1:31),"00"),0)]
 
Upvote 0
Or for your first example, something like:
Code:
   Me.ComboBox1.List = Array("01", "02", "03", "04") ' etc!
   ' or:
   Me.ComboBox1.List = [INDEX(TEXT(ROW(1:31),"00"),0)]

Rorya, I can't get the second example to work. I am unsure whether it is adding the number 1:31 direct from the code, or whether it is getting them from a worksheet?

Also, if I use the range example

Range("A3:A" & lastrow).Value</pre>
Can I format the whole range as "00"? I am not sure how I do that.
 
Upvote 0
What is the second example doing?

For the range, you can only get a formatted value if you loop and use the Text property of each cell or if you format the range as Text and then enter the values the way you want.
 
Upvote 0
What is the second example doing?

For the range, you can only get a formatted value if you loop and use the Text property of each cell or if you format the range as Text and then enter the values the way you want.

When I try it I get "Could not set the list property. Invalid property array index"
 
Upvote 0
Try this for the second one and tell me what it says/does:
Code:
   Dim varData
   varData = [INDEX(TEXT(ROW(1:31),"00"),0)]
   If IsArray(varData) Then
      Me.ComboBox1.List = varData
   Else
      MsgBox "Not an array"
   End If
 
Upvote 0

Forum statistics

Threads
1,224,591
Messages
6,179,768
Members
452,940
Latest member
rootytrip

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