VBA ListBox - get the value of the selected item and dislay it in a message box

I am displaying a few strings items on ListBox on a Form. I would like to display the value of the item (which is a string) displayed in a message box when I click on it. I would appreciate your help.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

NorieAnalyst Assistant Commented:
Private Sub ListBox1_Click()
    MsgBox ListBox1.Value
End Sub

Open in new window

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
FaheemAhmadGulAuthor Commented:
Thank you for your comment. This does not work, however. We need the value of the selected item and not of the ListBox - that is we want to display the value of the item on which the user clicks. This will involve finding out which item the user clicked on and then fidning its value.
NorieAnalyst Assistant Commented:
That code should show you the item that's been clicked in the listbox because Value returns the value of the selected item in the listbox.
Try it like this:
Private Sub ListBox1_Change()
    MsgBox ListBox1.List(ListBox1.ListIndex)
End Sub

Open in new window

FaheemAhmadGulAuthor Commented:
Many thanks. Actually both the solutions work. I have split the points - more points to Norie because that solution was post first. Hope this OK.
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 Office

From novice to tech pro — start learning today.