Extract data from listbox

kod2th3e

Board Regular
Joined
Apr 2, 2008
Messages
87
Is it possible to extract a value from the listbox? I have a listbox that populates automatically from a table on an excel sheet. It has 7 columns and the number of rows varies in length. I was wondering if I select a row from the listbox is it possible to extrapolate the value that resides in the first column of that row and assign it to a variable?

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]apple
[/TD]
[TD]red
[/TD]
[TD]round
[/TD]
[TD]asdf
[/TD]
[TD]asdf
[/TD]
[TD]sdff
[/TD]
[TD]1234
[/TD]
[/TR]
[TR]
[TD]pear
[/TD]
[TD]green
[/TD]
[TD]round
[/TD]
[TD]asdf
[/TD]
[TD]zxcv
[/TD]
[TD]jhkl
[/TD]
[TD]6543
[/TD]
[/TR]
[TR]
[TD]banana
[/TD]
[TD]yellow
[/TD]
[TD]oblong[/TD]
[TD]qwerqw
[/TD]
[TD]wer
[/TD]
[TD]fgdsd
[/TD]
[TD]0987
[/TD]
[/TR]
[TR]
[TD]kiwi
[/TD]
[TD]green
[/TD]
[TD]oval
[/TD]
[TD]qwerx
[/TD]
[TD]jh;ol
[/TD]
[TD]nm,.
[/TD]
[TD]8394
[/TD]
[/TR]
[TR]
[TD]orange
[/TD]
[TD]orange
[/TD]
[TD]round
[/TD]
[TD]aswef
[/TD]
[TD]nm.
[/TD]
[TD]nm.
[/TD]
[TD]2048
[/TD]
[/TR]
</tbody>[/TABLE]

Say the above table represents my listbox, I'd like to select the row with "1234" and have "apple" be assigned to a variable. Thanks in advance for any/all help, you're time is much appreciated.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
I have continued to dig around and found something that works for what I'm attempting, it is as follows:

Code:
lbl9.Caption = ListBox1.List(ListBox1.ListIndex, 0)

I used a label to display the result. The 0 (zero) at the end indicates which column you want to pull the data from within the selected row. It is zero based so if I wanted to display "1234" in the label I'd put the number 6 instead. I hope that someone else may find this information useful.
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top