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)
 

Some videos you may like

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
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
 

GTO

MrExcel MVP
Joined
Dec 9, 2008
Messages
6,154
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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,421
Messages
5,596,033
Members
414,039
Latest member
southike

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
Top