» Use listboxes with multiple choices using VBA in Microsoft Excel
VBA macro tip contributed by Erlandsen Data Consulting offering Microsoft Excel Application development, template customization, support and training solutions
CATEGORY - Files, Workbook, and Worksheets in VBA
VERSION - All Microsoft Excel Versions
The list with the chosen items in a multiple choice listbox is stored in the Selected-property of the listbox. The Selected-property returns an array with boolean values (True or False), one value for each item in the list.
Chosen items has the value True. To decide which items in the listbox that is chosen you will have to loop trough
the whole array and check each item to see if it's Selected-property is set to True.
Sub FindSelectedItems()
' finds selected items in ListBox1 in userform TestDialog in Excel97
Dim Msg As String, i As Integer
Msg = ""
With TestDialog.ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) Then
Msg = Msg & .List(i) & Chr(13)
End If
Next i
End With
MsgBox Msg, , "Selected items in ListBox1"
End Sub
Book Store:
Recommended Books:
- Definitive Guide to Excel VBA
- Microsoft Office Xp: Advanced Concepts and Techniques: Word 2002, Excel 2002, Access 2002, Powerpoint 2002
- Marketing Plans
- The Laws of Money, The Lessons of Life: Keep What You Have and Create What You Deserve
- Microsoft Excel VBA Programming for the Absolute Beginner
- The Ernst & Young Business Plan Guide
No comments have been submitted.

