View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Combobox | Add items | Object Required

Dim cbox as MSForms.Combobox
Dim ole as OleObject
Dim x as Long, i as Long

i = 1
x = 1

set ole = Activesheet.OleObjects("Combo_" & i & "_" & x)
set cbox = ole.Object
cbox.AddItem "1 - Pizza"
cbox.AddItem "2 - Chinese Food"

--
Regards,
Tom Ogilvy


"gduron" wrote in
message ...

I have several Combo boxes setup on my spread sheet with the following
naming conventions:

COMBO_<VARIABLE_<VARIABLE

So for example, one of my combo boxes is called: COMBO_1_1

Depending on certain criteria I want to populate one of the combo
boxes:

COMBO_1_1
COMBO_1_2
COMBO_1_3

What I can't figure out is how to reference my combo box as an object.

I could write the code like:

COMBO_1_1.AddItem "1 - Pizza"
COMBO_1_1.AddItem "2 - Chinese Food"

I want my code to be more dynamic than that though. I want to be able
to have variables where the numbers a

Dim i As Integer, x As Integer

i = 1
x = 1

COMBO_i_x.AddItem "1 - Pizza"
COMBO_i_x.AddItem "2 - Chinese Food"


If anyone can help me with this I would be much obliged.


--
gduron
------------------------------------------------------------------------
gduron's Profile:

http://www.excelforum.com/member.php...o&userid=33239
View this thread: http://www.excelforum.com/showthread...hreadid=537912