Simple Listbox Multiselect results capture

ToyB

New Member
Joined
Dec 15, 2010
Messages
3
On my excel userform I have two list boxes, one with peoples names and this transfers their email address into listbox2, which has multiselect activated, with a command button. That works fine.

I would like to know, in really simple coding :), how to convert the Listbox2 results into an array whereby the individual email addresses are separated by semicolons so I can put this into an email address field in outlook. I'm sure you can see what I am trying to do but the user selects who they want to email and then fires off a report to them.

Really appreciate your help
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Example:

Code:
Private Sub CommandButton1_Click()
    Dim First As Boolean
    Dim i As Long
    Dim List As String
    First = True
    With ListBox1
        For i = 0 To .ListCount - 1
            If .Selected(i) Then
                If First Then
                    List = .List(i)
                    First = False
                Else
                    List = List & ";" & .List(i)
                End If
            End If
        Next i
    End With
    MsgBox List
End Sub
 
Upvote 0
Hey Andrew thanks so much for this,

Works brilliantly except I found I need to highlight all the listbox results in blue for the code to recognise them being there. Is there an automatic way of doing this so that all the addresses are picked.

Example:

Code:
Private Sub CommandButton1_Click()
    Dim First As Boolean
    Dim i As Long
    Dim List As String
    First = True
    With ListBox1
        For i = 0 To .ListCount - 1
            If .Selected(i) Then
                If First Then
                    List = .List(i)
                    First = False
                Else
                    List = List & ";" & .List(i)
                End If
            End If
        Next i
    End With
    MsgBox List
End Sub
 
Upvote 0
Sure:

Code:
Private Sub CommandButton1_Click()
    Dim First As Boolean
    Dim i As Long
    Dim List As String
    First = True
    With ListBox1
        For i = 0 To .ListCount - 1
            If First Then
                List = .List(i)
                First = False
            Else
                List = List & ";" & .List(i)
            End If
        Next i
    End With
    MsgBox List
End Sub
 
Upvote 0
Thank you again and for such a quick reply. Much appreciated.

Works just like I hoped it would
 
Upvote 0

Forum statistics

Threads
1,215,472
Messages
6,125,011
Members
449,204
Latest member
tungnmqn90

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