Put items in combobox using VBA and toolbox

  • Thread starter Thread starter JoeS01
  • Start date Start date
J

JoeS01

I wish to create a simple drop down menu using VBA. I do not wish to pu
an array of the item names to one side of the spreasheet and link t
that, but put the item names in by using VBA . I am not working from
UserForm, but using Toolbox and the VB Editor.

I have created a combobox as a start :)

So far I have tried the following without success:

Private Sub Forms.ComboBox1_Change()
With ComboBox1
.ListFillRange = ""
'.AddItem "X"
'.AddItem "Y"
'.AddItem "Z"
'.AddItem "X2"
'.AddItem "Y2"
'.AddItem "Z2"
End With

End Sub

All assistance and suggestions gratefully accepte
 
The ' before the AddItem lines are not there in my code - it was
leftover from my testing :eek
 
The code would look something like this

Sub ComboBox1_Load()
With ComboBox1
.AddItem "X"
.AddItem "Y"
.AddItem "Z"
.AddItem "X2"
.AddItem "Y2"
.AddItem "Z2"
.ListIndex = 0
End With
End Sub

You would have a separate routine to load it at start, unlikely to use an
event procedure to load it.
 
Back
Top