Combo Boxes and VBA


Posted by Michael on December 17, 2001 1:47 PM

How do I define a variable in a macro to equal the text that someone selects from a combo box on the main spreadsheet?



Posted by Juan Pablo G. on December 17, 2001 8:11 PM

Well, that depends. If it's a Form commandbar you would need to link your variable to the linked cell of the combobox, something like

YourVar = Range("A1")

If A1 is the linked cell of the Combo Box. If you're working with one of the Control Toolbox toolbar then you could use (If you really want a variable to do this)

YourVar = ComboBox1

or to get the Number (From 0 to ListCount - 1) of the selected item

YourVar = ComboBox1.ListIndex

If it returns -1 then nothing is selected.

Juan Pablo G.