fmMultiSelectMulti

tony.reynolds

Board Regular
Joined
Jul 8, 2010
Messages
97
i have a userform with a Listbox

the form has worked really well now i want to be able to select more than one of the options

Thats fine ive selected multiSelectMulti and i can now select multipule entries. but how ever dou you get from the list box which ones are selected?

The Listbox1.Value dosnt seem to be ther anymore??

Please enlighten me as to how to get the data even if it is a sequence number (like selections=1,3,7)
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try like this

Code:
For i = 0 To ListBox1.ListCount - 1
    If ListBox1.Selected(i) Then
        'the selected value is true if the item is selected
        MsgBox ListBox1.List(i) & " selected"
    End If
Next i
 
Upvote 0
Check out .Selected and .List in vba help. A simple example with one commandbutton and one listbox, both using default names:
Rich (BB code):
Option Explicit
    
Private Sub CommandButton1_Click()
Dim i As Long
Dim myString As String
    
    With Me.ListBox1
        If .ListCount > 0 Then
            For i = 0 To .ListCount - 1
                If .Selected(i) Then
                    myString = myString & vbLf & .List(i)
                End If
            Next
            MsgBox "You picked: " & myString
        End If
    End With
End Sub
Private Sub UserForm_Initialize()
    With Me.ListBox1
        .MultiSelect = fmMultiSelectExtended
        .List = Array("Item 1", "Item 2", "Item 3", "Item 4", "Item 5", "Item 6", "Item 7", "Item 8")
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,413
Messages
6,119,372
Members
448,888
Latest member
Arle8907

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top