Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default comboboxes, extracting specific item

Hello,
I'm trying to populate a combo box with two columns and an unknown
number of rows. I would like to populate the items using a reference
to row and column, such as box(nrow,ncol)="X". This code would
ideally put the value "X" into the combo box at the specified row and
column. In short, I would like to write to and access the box as if
it were an array.

And..once populated, I would like to be able to pull values out based
on column. So, if I had a box containing:

"Peanuts" 1
"Cashews" 3
"Brazil Nuts" 2

If someone selected "Cashews", I would like to access the number 3
which is associated with "Cashews".

Can someone explain how to do something like this?

thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default comboboxes, extracting specific item

After serious thinking Andrew wrote :
Hello,
I'm trying to populate a combo box with two columns and an unknown
number of rows. I would like to populate the items using a reference
to row and column, such as box(nrow,ncol)="X". This code would
ideally put the value "X" into the combo box at the specified row and
column. In short, I would like to write to and access the box as if
it were an array.

And..once populated, I would like to be able to pull values out based
on column. So, if I had a box containing:

"Peanuts" 1
"Cashews" 3
"Brazil Nuts" 2

If someone selected "Cashews", I would like to access the number 3
which is associated with "Cashews".

Can someone explain how to do something like this?

thanks


Set your BoundColumn property to 2 so when someone selects "Cashews" it
returns the value in the next column. you could even hide the 2nd
column (set Width to 0pt.) so users only see the product list.

HTH

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 259
Default comboboxes, extracting specific item

Hi Andrew

you could try Debra Dalgliesh's DataValidation code.

It shows you how to setup a Dependant List using INDEX/MATCH.

http://www.contextures.com/xlDataVal15.html

I use it as a means of filtering departments and who is in them.

HTH
Mick.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default comboboxes, extracting specific item

On Jul 5, 10:50*am, GS wrote:
After serious thinking Andrew wrote :



Hello,
I'm trying to populate a combo box with two columns and an unknown
number of rows. *I would like to populate the items using a reference
to row and column, such as box(nrow,ncol)="X". *This code would
ideally put the value "X" into the combo box at the specified row and
column. *In short, I would like to write to and access the box as if
it were an array.


And..once populated, I would *like to be able to pull values out based
on column. *So, if I had a box containing:


"Peanuts" * *1
"Cashews" * 3
"Brazil Nuts" 2


If someone selected "Cashews", I would like to access the number 3
which is associated with "Cashews".


Can someone explain how to do something like this?


thanks


Set your BoundColumn property to 2 so when someone selects "Cashews" it
returns the value in the next column. you could even hide the 2nd
column (set Width to 0pt.) so users only see the product list.

HTH

--
Garry

Free usenet access athttp://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


It sounds like we are talking about the same thing, but I don't
understand your response. How do I get a number into the second
column? I'd like to access the elements of the list just as if it
were an array, where I can write to or read from it based on column
and row indices. How is that done with a combobox?
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 587
Default comboboxes, extracting specific item

hi,

'ListIndex property Identifies the currently selected item
'0 is first column index
'1 is column index 2

Private Sub ComboBox1_Change()
With ActiveSheet.ComboBox1
MsgBox .List(.ListIndex, 1)
End With
End Sub


--
isabelle



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default comboboxes, extracting specific item

Andrew pretended :
On Jul 5, 10:50*am, GS wrote:
After serious thinking Andrew wrote :



Hello,
I'm trying to populate a combo box with two columns and an unknown
number of rows. *I would like to populate the items using a reference
to row and column, such as box(nrow,ncol)="X". *This code would
ideally put the value "X" into the combo box at the specified row and
column. *In short, I would like to write to and access the box as if
it were an array.


And..once populated, I would *like to be able to pull values out based
on column. *So, if I had a box containing:
"Peanuts" * *1
"Cashews" * 3
"Brazil Nuts" 2


If someone selected "Cashews", I would like to access the number 3
which is associated with "Cashews".


Can someone explain how to do something like this?
thanks


Set your BoundColumn property to 2 so when someone selects "Cashews" it
returns the value in the next column. you could even hide the 2nd
column (set Width to 0pt.) so users only see the product list.

HTH

--
Garry

Free usenet access athttp://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


It sounds like we are talking about the same thing, but I don't
understand your response. How do I get a number into the second
column? I'd like to access the elements of the list just as if it
were an array, where I can write to or read from it based on column
and row indices. How is that done with a combobox?


The simplest way is to put your data into an array and then assign the
array to the list.

Example:
Dim vaData As Variant

'Get list items from worksheet
vaData = ActiveSheet.Range("$A$1:$B$3") 'revise to suit
'Note that this is a 2D array consisting of 3 rows by 2 cols
'vaData(1, 1) contains "Peanuts"; vaData(1, 2) contains '1'
'vaData(2, 1) contains "Cashews"; vaData(2, 2) contains '3'
'vaData(2, 1) contains "Brazil Nuts"; vaData(2, 2) contains '2'

'Assign list to combobox
ComboBox1.List = vaData
'.List(0, 0) = "Peanuts"; .List(0, 1) = '1'
'.List(0, 0) = "Cashews"; .List(0, 1) = '3'
'.List(0, 0) = "Brazil Nuts"; .List(0, 1) = '2'
'Syntax: .List(nRow, nCol) = x

Now, with BoundColumn set to 2, when a user selects "Cashews" the value
returned is 3. If you set the ColumnWidth property to 50pt,0pt then
the user won't see the 2nd column.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 130
Default comboboxes, extracting specific item

On Jul 6, 8:16*am, GS wrote:
Andrew pretended :



On Jul 5, 10:50*am, GS wrote:
After serious thinking Andrew wrote :


Hello,
I'm trying to populate a combo box with two columns and an unknown
number of rows. *I would like to populate the items using a reference
to row and column, such as box(nrow,ncol)="X". *This code would
ideally put the value "X" into the combo box at the specified row and
column. *In short, I would like to write to and access the box as if
it were an array.


And..once populated, I would *like to be able to pull values out based
on column. *So, if I had a box containing:
"Peanuts" * *1
"Cashews" * 3
"Brazil Nuts" 2


If someone selected "Cashews", I would like to access the number 3
which is associated with "Cashews".


Can someone explain how to do something like this?
thanks


Set your BoundColumn property to 2 so when someone selects "Cashews" it
returns the value in the next column. you could even hide the 2nd
column (set Width to 0pt.) so users only see the product list.


HTH


--
Garry


Free usenet access athttp://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


It sounds like we are talking about the same thing, but I don't
understand your response. *How do I get a number into the second
column? *I'd like to access the elements of the list just as if it
were an array, where I can write to or read from it based on column
and row indices. *How is that done with a combobox?


The simplest way is to put your data into an array and then assign the
array to the list.

* Example:
* Dim vaData As Variant

* 'Get list items from worksheet
* vaData = ActiveSheet.Range("$A$1:$B$3") 'revise to suit
* 'Note that this is a 2D array consisting of 3 rows by 2 cols
* 'vaData(1, 1) contains "Peanuts"; vaData(1, 2) contains '1'
* 'vaData(2, 1) contains "Cashews"; vaData(2, 2) contains '3'
* 'vaData(2, 1) contains "Brazil Nuts"; vaData(2, 2) contains '2'

* 'Assign list to combobox
* ComboBox1.List = vaData
* '.List(0, 0) = "Peanuts"; .List(0, 1) = '1'
* '.List(0, 0) = "Cashews"; .List(0, 1) = '3'
* '.List(0, 0) = "Brazil Nuts"; .List(0, 1) = '2'
* 'Syntax: .List(nRow, nCol) = x

Now, with BoundColumn set to 2, when a user selects "Cashews" the value
returned is 3. If you set the ColumnWidth property to *50pt,0pt *then
the user won't see the 2nd column.

--
Garry

Free usenet access athttp://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


This is perfect. Exactly what I was looking for. Thanks for your
help.

Andy
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default comboboxes, extracting specific item

You're very welcome! Always glad to be of help wherever I can...

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


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
Show Specific Item in Specific Field Bryan Excel Programming 0 April 3rd 08 09:06 PM
extracting specific rows wynand Excel Discussion (Misc queries) 6 January 29th 08 01:15 PM
extracting specific rows wynand Excel Discussion (Misc queries) 9 January 29th 08 11:33 AM
Count Specific Item in Specific Row RayH Excel Discussion (Misc queries) 9 July 23rd 06 07:48 PM
Removing specific entries from comboboxes Tim[_39_] Excel Programming 0 October 24th 04 01:33 PM


All times are GMT +1. The time now is 04:06 PM.

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

About Us

"It's about Microsoft Excel"