11

I am new to VBA. I want to create a form where a user selects an item of a combobox and the selection runs a macro.I created a user form in VBA but I am unable to add items to the Combobox.When a user opens the form I want the choices in the combobox to be already loaded.how can I accomplish this?

Thank You

lfrandom
  • 1,013
  • 2
  • 10
  • 32
srk
  • 427
  • 4
  • 11
  • 27

3 Answers3

22

The method I prefer assigns an array of data to the combobox. Click on the body of your userform and change the "Click" event to "Initialize". Now the combobox will fill upon the initializing of the userform. I hope this helps.

Sub UserForm_Initialize()
  ComboBox1.List = Array("1001", "1002", "1003", "1004", "1005", "1006", "1007", "1008", "1009", "1010")
End Sub
Brandon
  • 68,708
  • 30
  • 194
  • 223
daChizzle
  • 231
  • 2
  • 6
  • Is there a way to create a combobox dynamically in VBA? I need to create one at run-time inside sheet1 whenever the workbook opens. Appreciate any pointers on this. – ashwani kumar Sep 01 '21 at 04:23
5

Here is another answer:

With DinnerComboBox
.AddItem "Italian"
.AddItem "Chinese"
.AddItem "Frites and Meat"
End With 

Source: Show the

Andrii
  • 2,843
  • 27
  • 33
4

I found this;

Excel VBA ComboBox Lists

from here;

vba- Can a combobox present more then one column on it's textbox part?

and this may help;

Populating ComboBoxes VBA

I added a sort of demo here;

Playing with populating boxes.xlsm

Community
  • 1
  • 1
MakeCents
  • 742
  • 1
  • 5
  • 15