ERLANDSEN DATA CONSULTING Excel & VBA Tips   Informasjon på norsk / Information in Norwegian

These pages are no longer updated and are only available for archive purposes.

Click here to visit the pages with updated information.

Use listboxes with multiple choices

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.

Here is an example macro for Excel97:

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

Here is an example macro for Excel5/95:

Sub FinnValgteElementer()
Dim dlg As DialogSheet
Dim lb As ListBox
Dim msg As String
Dim iCount As Integer
    Set dlg = ThisWorkbook.DialogSheets("Dialog1")
    Set lb = dlg.ListBoxes(1)
    msg = "Selected items:" & Chr(13)
    If dlg.Show Then
        For iCount = 1 To lb.ListCount
            If lb.Selected(iCount) Then
                msg = msg & lb.List(iCount) & Chr(13)
            End If
        Next iCount
        MsgBox msg, , "Selected items in ListBox(1)"
    End If
End Sub

 

Document last updated 2000-02-05 12:47:20      Printerfriendly version

 

Erlandsen Data Consulting     http://www.erlandsendata.no/   
Excel & VBA Tips   Copyright ©1999-2017    Ole P. Erlandsen   All rights reserved
E-mail Contact Address