View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default finding line number selected in combo box

The ListIndex property of ListBox (same for a ComboBox by the way) will tell
you which item number is selected; but note the index it zero based, so the
first item in the list is 0, the second item is 1, etc. Also, if the
ListIndex is equal to -1 (minus one), then no item is selected. You can get
the text of a particular item in the list by using the List property; so,
the text for the fifth item in a list is ListBox1.List(4)... this can be
handy in a For..Next loop. Also, you can get the text for the select item
using ListBox1.List(ListBox1.ListIndex).

--
Rick (MVP - Excel)


"Bonsai Bill" wrote in message
...
I am trying a combo box for the first time so my question is hopefully
trivial. I am using two combo boxes. The first is simple and has six
simple
two or three word descriptors. Based upon selection in first combo box I
"load" the second combo box which has longer text in items. Macros will be
used in Excel 2007.

I am using rowsource to load the lists and I also put in the most likely
response via values. I can determine which value is selected in the boxes
using a string comparison which is a bit messy. Is there a variable that
can
tell me which line number in the combo box was selected? That would a much
cleaner way.

One other trivial question: Rowsource requires a string and I see how to
to
provide information using sheet numbers. What is syntax for using sheet
names
instead?

Thanks in advance for your help! You folks provide a valuable service to
us
with less experience.