Textbox Based On Selected Listbox Rows

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,060
Can someone please help with the following.

I have a listbox which is filled with email addresses, I would like a script which once I have selected rows that I want in a multiselect listbox it will then put all the email addresses into a textbox as follows

say the listbox has the following email addresses (and many many more).

jim@mymail.com
frank@mymail.com
sue@mymail.com
sarah@mymail.com
bob@mymail.com

I multi select jim, sarah, bob (and possibly many others) it then puts the values in the textbox as follows.

jim@mymail.com; sarah@mymail.com; bob@mymail.com

Thank you.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
somthing like this maybe...though not sure
for example D1=A1&";"&A2&";"&A3

textbox1.value = range("D1").value
......
 
Last edited:
Upvote 0
Code:
Const Delmiter As String = ";"
Dim i As Long

TextBox1.Text = vbNullString

With ListBox1
    For i = 0 to .ListCount - 1
        If .Selected(i) Then
            TextBox1.Text = TextBox1.Text & Delimiter & .List(i)
        End If
    Next i
End With

TextBox1.Text = Mid(TextBox1.Text, Len(Delimiter) + 1)
 
Upvote 0
Thanks for your help Pedie and Mike.

I went with Mike's script as the data is based on listbox and textbox data not upon any text in the sheet and I didn't want to add the text to the sheet etc...

I had to change the delimiter script to ";" as it wasn't putting a delimiter between the email addresses and now it workes exactly the way that I wanted it to.

Thanks Mike, much appreciated, 2 days in a row you have provided great scripts, much appreciated. :):):)
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,639
Members
449,093
Latest member
Ahmad123098

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