Put items in combobox using VBA and toolbox

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
 
J

JoeS01

The ' before the AddItem lines are not there in my code - it was
leftover form my testin
 
J

JoeS01

The ' before the AddItem lines are not there in my code - it was
leftover from my testing :eek
 
B

Bob Phillips

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top