Excel 2013 ListBox event

I'm working with excel VBA 2013 and multiselect listbox.

Whenever a user selects or deselects and item in the list box I would like to fire an event that gets me the value of that item and whether or not it was selected.  Is there an event trigger that tells which item was clicked on without having to cycle through all items in the list?
LVL 6
HyperBPPAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Roy CoxGroup Finance ManagerCommented:
I don't thinks so. The code must loop through the contents to find which item(s) are selected.
0
Rgonzo1971Commented:
Hi,

pls try EDITED Code

Private Sub ListBox1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
     
    Dim lListRow As Long
     
    If Button = 1 Then
         
        lListRow = (Y / g_sLBRwHeight) + 0.5 + ListBox1.TopIndex - 1
        If lListRow > (ListBox1.ListCount - 1) Then lListRow = ListBox1.ListCount - 1
        MsgBox "Element " & ListBox1.List(lListRow) & ": " & IIf(ListBox1.Selected(lListRow), "Selected", "Not Selected")
         
    End If
     
End Sub
 
Private Sub UserForm_Activate()
     
    Dim sOldHeight
     
    If g_sLBRwHeight = 0 Then
        With ListBox1
            .TopIndex = .ListCount - 1
            sOldHeight = .Height
            Do While .TopIndex = 0
                .Height = .Height - 10
                .TopIndex = .ListCount - 1
            Loop
            g_sLBRwHeight = .Height / (.ListCount - .TopIndex + 1)
            .Height = sOldHeight
            .TopIndex = 0
        End With
    End If
     
End Sub

Open in new window

Regards
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.