Filling a Combo Box with VBA

  • Thread starter Thread starter Ed
  • Start date Start date
E

Ed

How can I fill a ComboBox with two items, say "X"
and "Y", using VBA?

All help is appreciated
 
Hi,

Add a userform in the VBA Editor called UserForm1
On that userfom add a combo box called ComboBox1
Write this code in the userform:s Initialize event:

Private Sub UserForm_Initialize()

With ComboBox1
.AddItem "X"
.AddItem "Y"
' Set default text.
.Text = "X"
End With

End Sub

Add a module and write this code in the module in order to show the
userform.

Sub TestForm()
UserForm1.Show
End Sub


HTH
/Ulrik

..
 
Ed said:
How can I fill a ComboBox with two items, say "X"
and "Y", using VBA?

If you want it at the initialization, you need to use the Initialize event:

Private Sub UserForm_Initialize()
ComboBox1.AddItem "X"
ComboBox1.AddItem "Y"
End Sub

But in general: ComboBox1.AddItem "X"

Regards,
 
Back
Top