Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding/Selecting a Value in an Excel List Box

Status
Not open for further replies.

GGleason

Technical User
Mar 22, 2001
321
US
I have a list box on an Excel worksheet. I want to find a particular value in that list and make sure it is the one selected. How do I do this? The help has not been helpful.

tia,
GGleason
 
I think this is what you are asking:
Code:
  If ListBox1.Value = "Clive" Then
    MsgBox "Item matched"
  Else
    MsgBox "Item not matched"
  End If

This basically checks to see if the currently selected item is equal to "Clive". Actually, both ListBox1.Text and ListBox1.Value store the currently selected item.

Let me know if this wasn't what you were actually asking!

Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
It depends on where you got the list box. Did you use the "Control Toolbox" toolbar or the "Forms" toolbar?

See thread707-585411 for a discussion on the differences. (With one you can access the value directly. With the other you use the index number.)

 
Clive,

Unfortunately that suggestion does not work.

This list box is on the spreadsheet, not on a form, so I think that the code is going to be something like ...
[tt]
ActiveSheet.Shapes("lstTime")...
[/tt]
Thanks,
GGleason
 
My suggestion works fine: I added a ListBox from the Control Toolbox directly onto a spreadsheet, not a form. Did Zathras' suggestions in his link not solve your problem?

Could you specify a bit more information i.e. exactly what do you want to do? And what method did you use to add the listbox to the spreadsheet?

Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
Zathras,

The thread you supplied had what I was looking for. The solution was way simpler than I was making it out to be.

Clive,

I think that the problem was I should have used [tt].Text[/tt] instead of [tt].Value[/tt].

Thanks to both of you,
GGleason
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top