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?

apple
red
round
asdf
asdf
sdff
1234
pear
green
round
asdf
zxcv
jhkl
6543
banana
yellow
oblongqwerqw
wer
fgdsd
0987
kiwi
green
oval
qwerx
jh;ol
nm,.
8394
orange
orange
round
aswef
nm.
nm.
2048

<tbody>
</tbody>

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

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
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,215,326
Messages
6,124,256
Members
449,149
Latest member
mwdbActuary

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