Article ID: 111564
Article Last Modified on 10/10/2006
False, True, True, False
A1: Alpha
A2: Bravo
A3: Charlie
A4: Delta
A5: Echo
A6: Foxtrot
A7: Golf
A8: Hotel
'----------------------------------------------------------------------
Sub ShowSelectedItems()
' Dimension variables.
Dim CurList As ListBox, Chosen As Integer
Dim LTemp As Variant, LItem As Variant
Dim Counter As Integer, MsgBoxText As String
' Set an object name for the list box to make it
' easier to reference.
Set CurList = _
DialogSheets("Dialog1").ListBoxes("List1")
' Initialize the list so that none of the items are
' selected.
CurList.Selected = _
Array(False, False, False, False, False, False, False, False)
' Show the dialog box and set variable 'chosen' to
' the value returned by the dialog box.
chosen = DialogSheets("Dialog1").Show
' If cancel is chosen, exit the procedure.
If chosen = 0 Then GoTo canceled
' Set the variable LTemp equal to the array of values
' indicating the selection state of the list box items.
LTemp = CurList.Selected
' Initialize the Counter variable.
Counter = 1
' Iterate through the loop once for each item in the
' array (which is the same as iterating once for each
' item in the list box).
For Each LItem In LTemp
' If the value of the current item is True...
If LItem = True Then
' Add text to the MsgBoxText variable indicating
' that the item is selected.
' CurList.List(Counter) returns the text of the selected item
' ("Alpha", "Bravo", and so on).
MsgBoxText = MsgBoxText & CurList.List(Counter) & _
" is selected. " & Chr(13)
' Otherwise...
Else
' Add text to the MsgBoxText variable indicating that
' the item is not selected.
' CurList.List(Counter) returns the text of the unselected item
' ("Alpha", "Bravo", and so on).
MsgBoxText = MsgBoxText & CurList.List(Counter) & _
" is NOT selected. " & Chr(13)
End If
' Increment the Counter so we can get the value of the
' next selected item.
Counter = Counter + 1
' Repeat until all the items in the list have
' been checked.
Next
' Display a dialog box indicating the selection state
' of each item in the list.
MsgBox MsgBoxText
' If the Cancel button was chosen, exit procedure.
canceled:
End Sub
'----------------------------------------------------------------------
Sheets("Sheet1").Cells(10, 10).Value = CurList.List(Counter)
Additional query words: 5.00c howto multiple dropdown XL97 XL7 XL5 XL
Keywords: kbcode kbhowto kbprogramming KB111564