Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing ComboBox indirectly using variable

Status
Not open for further replies.

baronvont

Technical User
May 15, 2001
77
0
0
AU
Hi,

I am trying to reference a particular combobox in excel.

I know you can use a variable to reference cells etc such as:

For var = 1 to 10
range("A" & var).select
....
next

but what about a combobox. I need to be able to change the value in a particular combobox out of a range of boxes, but this won't work (ie need to get to combobox5):

var = 5
combobox & var = somevalue
nor will
"combobox" & var = somevalue

So has anyone got a bright idea?

thanks
GT
 
GT,

Assuming your combobox is on a Userform, try something like this:
Code:
var = 5
UserForm1.Controls("ComboBox" &var).Value = Somevalue

Regards,
Mike
 
No, it's on the sheet it'self. There are 90 combos in total (3 per row, one row per month) combobox1-90

Thanks
Georg
 
Georg,

OK. Try the following, then:
Code:
var = 5
Worksheets("SheetName").OLEObjects("ComboBox" & var).Object.Value = SomeValue

Mike
 
Mike

Not quite - came up with 'Subscript out of range'
After I changed it to this it worked...

Activesheets.OLEObjects("ComboBox" & var).Object.Value

Many thanks
Georg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top