sooprise
sooprise

Reputation: 23187

Adding Items To A Combo Box Without Code?

I want some default values in my combo boxes but can't seem to figure out how to do this without writing a module that populates the combo boxes. How can I manually fill in the combo boxes so I don't have to use code to do something so simple.

Thanks

Upvotes: 2

Views: 19462

Answers (4)

Jayson
Jayson

Reputation: 1

You could also try something like

Private Sub worksheet_Activate()

With Sheet1.ComboBox1 .List = Range("a1:a20").Value End With 'This will give a list of the values from Cell A1 to Cell A20 End Sub

Upvotes: 0

Jay
Jay

Reputation: 57919

What program are you using? Where is the combobox. For example, in Excel, you can have a combobox on a form or on the worksheet, and the answer is going to depend on these factors.

In Excel, you can define your default values in a worksheet (which you can hide, if you want), and set the combo box source to the corresponding range -- no code required.

Please elaborate on your requirements and you'll get more specific answers.

Upvotes: 2

iDevlop
iDevlop

Reputation: 25252

I guess you speak about Access ? If that's the case,

  • set the Row Source Type to "Value List"
  • then set the Row Source to Black; Blue; Green or whatever you want

Upvotes: 2

Hans Olsson
Hans Olsson

Reputation: 55009

If I understand you question correctly, I'm fairly sure you have to have code somewhere, I don't think VBA supports as I seem to remember that VB6 did to just add the items in a property, but you don't have to create a separate module, just something like this should work:

Private Sub UserForm_Activate()
    ComboBox1.AddItem "Text1"
    ComboBox1.AddItem "Text2"
    ComboBox1.AddItem "Text3"
End Sub

Upvotes: 0

Related Questions