Combo box

P

pokdbz

I have a variable named WhichCombo. This has a name of a combo box it in to
be used in the statment below.
When I try this there is an error. How do I use the variable in the
statment below for the combo box?

Sheets("Sheet1").WhichCombo.AddItem Item
 
D

Dave Peterson

I used a combobox from the Control Toolbox toolbar. Is that what you used?

Option Explicit
Sub testme02()

Dim WhichCombo As String
Dim myItem As String
WhichCombo = "Combobox1"

myItem = "hi there"

Worksheets("Sheet1").OLEObjects(WhichCombo).Object.AddItem myItem
End Sub

Item looks too much like VBA's .Item property. I wouldn't use it as a variable
name.
 
P

pokdbz

Yep thats what I needed.

Dave Peterson said:
I used a combobox from the Control Toolbox toolbar. Is that what you used?

Option Explicit
Sub testme02()

Dim WhichCombo As String
Dim myItem As String
WhichCombo = "Combobox1"

myItem = "hi there"

Worksheets("Sheet1").OLEObjects(WhichCombo).Object.AddItem myItem
End Sub

Item looks too much like VBA's .Item property. I wouldn't use it as a variable
name.
 
Top