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

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Lewiy

Well-known Member
Joined
Jan 5, 2007
Messages
4,284
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!
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,357
Office Version
  1. 365
Platform
  1. Windows
Couldn't you use the listboxes ListIndex property?
 

Forum statistics

Threads
1,181,405
Messages
5,929,756
Members
436,687
Latest member
Glass of Gin

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
Top