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 did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

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,155
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,946
Messages
5,856,451
Members
431,815
Latest member
saradickinson25

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