Excel VBA question: How can I use vba to access a listbox?
-
I can't find the answer to this anywhere. I have a listbox displayed in my workbook (note: in my workbook, not in a form). This listbox has 10 values in it, and I have given the option of selecting more than one value. I am now writing a macro that accesses the data chosen by the user. I cannot find a way to access the list box. If I set the list box to only allow one selection then there is a Cell Link option that will output the results to another cell, however when I set the list box to multi select it will only output a 0 to this cell, thus I can't access the information this way. I need a way to get at this information via VBA. I'm good at VBA and excel, so a quick and simple example that works is all I need. Note: the name of my list box is 'MetricLB' Thanks! David
-
Answer:
The Cell Link is ignored for a MultiSelect List Box. You have to access the selected items in code. Test the Selected property of each item in the List to determine which items are selected. Private Sub ListChoices() Dim i As Integer Dim cnt As Integer ' Get the number of items in the list cnt = ListBox1.ListCount ' Loop through the items, checking each one ' to see if it is selected For i = 0 To (cnt - 1) If ListBox1.Selected(i) = True Then Debug.Print ListBox1.List(i) End If Next i End Sub Additional Resources: Look at Excel VBA Help for the ActiveX ListBox Object - Hammer
davidparks21-ga at Google Answers Visit the source
Related Q & A:
- How can I use a button to retrieve a phone 'number' from contacts?Best solution by Stack Overflow
- How Can I Use A Picture For My Avatar?Best solution by Yahoo! Answers
- How can I use my PC with a wireless printer?Best solution by pcmag.com
- How can i use my laptop as a monitor for my xbox 360?Best solution by Yahoo! Answers
- How can I use a prepaid credit card?Best solution by ehow.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.