Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default finding line number selected in combo box

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
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.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default finding line number selected in combo box

I'm not sure why I thought you asked about a ListBox, but every thing I said
applies to a ComboBox as well... they use the same addressing scheme (mainly
because underneath it all, a ComboBox is really a ListBox combined with a
TextBox).

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
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.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default finding line number selected in combo box

Thanks Rick. It works well and eliminates some potentially dodgy code.

Can you offer comparable help on:
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? I can always activate a sheet to use the Rowsource but there must
be an easy way to put in the name-a way that I have not guessed yet.

Thanks for your quick and right-on response!

"Rick Rothstein" wrote:

I'm not sure why I thought you asked about a ListBox, but every thing I said
applies to a ComboBox as well... they use the same addressing scheme (mainly
because underneath it all, a ComboBox is really a ListBox combined with a
TextBox).

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
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.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default finding line number selected in combo box

I think you want something like this...

ComboBox1.RowSource = Worksheets("Sheet4").Range("A1:A4").Address

where you would use your worksheet's actual name and change the range
address to match your actual row source. You can also do it directly like
you would in the Properties window itself...

ComboBox1.RowSource = "Sheet4!A1:A4"

It kind of depends on whether the row source can be variable (my first
example) or fix (my second example) although, of course, you can dynamically
construct the String value in the second example if you want.

--
Rick (MVP - Excel)


"Bonsai Bill" wrote in message
...
Thanks Rick. It works well and eliminates some potentially dodgy code.

Can you offer comparable help on:
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? I can always activate a sheet to use the Rowsource but there must
be an easy way to put in the name-a way that I have not guessed yet.

Thanks for your quick and right-on response!

"Rick Rothstein" wrote:

I'm not sure why I thought you asked about a ListBox, but every thing I
said
applies to a ComboBox as well... they use the same addressing scheme
(mainly
because underneath it all, a ComboBox is really a ListBox combined with a
TextBox).

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
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.






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default finding line number selected in combo box

Hi Rick,
Your first response is exactly what I need as the ranges are dynamic.

I appreciate your help. I am glad to have some new tricks to use!


"Rick Rothstein" wrote:

I think you want something like this...

ComboBox1.RowSource = Worksheets("Sheet4").Range("A1:A4").Address

where you would use your worksheet's actual name and change the range
address to match your actual row source. You can also do it directly like
you would in the Properties window itself...

ComboBox1.RowSource = "Sheet4!A1:A4"

It kind of depends on whether the row source can be variable (my first
example) or fix (my second example) although, of course, you can dynamically
construct the String value in the second example if you want.

--
Rick (MVP - Excel)


"Bonsai Bill" wrote in message
...
Thanks Rick. It works well and eliminates some potentially dodgy code.

Can you offer comparable help on:
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? I can always activate a sheet to use the Rowsource but there must
be an easy way to put in the name-a way that I have not guessed yet.

Thanks for your quick and right-on response!

"Rick Rothstein" wrote:

I'm not sure why I thought you asked about a ListBox, but every thing I
said
applies to a ComboBox as well... they use the same addressing scheme
(mainly
because underneath it all, a ComboBox is really a ListBox combined with a
TextBox).

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
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.





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change the line color based on the value selected in combo box Avinash Excel Programming 1 July 5th 06 09:50 PM
selected value is not saved in combo box MarkDev Excel Discussion (Misc queries) 2 June 20th 06 09:41 PM
saving combo box selected value MarkDev New Users to Excel 0 June 19th 06 06:45 PM
Finding the minimum in a selected number of rows of the same colum Mark Rugers Excel Worksheet Functions 5 July 20th 05 10:37 PM
Displaying a selected value from a combo box LHaro Excel Programming 2 June 10th 05 03:15 AM


All times are GMT +1. The time now is 07:43 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"