obtain value from selected listbox item


I have listbox with values, if I click on the selected value I get a message showing the depicted list box item from the list  i.e. like so:

Private Sub ListBox1_Click()
MsgBox "Selected Value is " & ListBox1.Value & ""

1) how do I get the select value to display in an excek worksheet i.e. on sheet 1 field b1?
2) how do I get a listbox1.value to display and parse in SQL statement on a DB connection i.e.:


would be glad for your assistance

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.

Since the correct value is appearing, you should be able to do this to add it to Excel:

Sheets(1).range("B1").value = ListBox1.Value

Open in new window

And to add it to SQL:


Open in new window

(This if PARAMETER is numeric)

strSQL = "SELECT * FROM MYTABLE WHERE PARAMETER = '" & ListBox1.Value & "'"

Open in new window

(This if your PARAMETER is a string rather than a number.)

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
rutgermonsAuthor Commented:
the paramtere could be dates too! the above seem nearly there but doesnt display on the below (this is the selected value in the valuelist)

"Backlog 01208 - Backlog request thru 12/08/13"
For dates you want to use "#" as delimiters, I think:

strSQL = "SELECT * FROM MYTABLE WHERE PARAMETER = #" & ListBox1.Value & "#"

Open in new window

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.