Clicking on a row in a listbox

conorohio

New Member
Joined
Jul 25, 2007
Messages
5
Hi,
I'm using excel 2003 Windows XP, and I'm trying to trigger an event, when clicking in a list box, that is specific to the row I click on.

Although I know the list box can tell which row I click on since that row will highlight, I see no function or property that would allow me to return the number of the row that was clicked.

One way to do this would be to use the X and Y values returned by mousedown/mouseup to figure it out, however because my listbox has a scrollbar these values won't always determine the correct rows.

Does anyone know how to do this?

Thanks
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
The ListBox has a property called ListIndex which returns the current position in the list (this starts from 0 being the first item in the list). As an example, use the following code behind the ListBox:
Code:
Private Sub ListBox1_Click()
MsgBox ListBox1.ListIndex
End Sub
Now when you click one of the items in the ListBox, a box will appear telling you what the index number of the item in the list is.

Hope that helps!
 
Upvote 0
Couldn't you use the listboxes ListIndex property?
 
Upvote 0

Forum statistics

Threads
1,214,429
Messages
6,119,433
Members
448,897
Latest member
ksjohnson1970

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