Copying selected items from Listbox into Textbox

A

Alan T

I have a userform (uf1) which contains a button which will displa
another userform (uf2) when selected.

On uf2 I have a listbox which populates with with a number of colleagu
names when it opens. The listbox (lb1)is configured to allow selectio
of more than one name at a time. Also on uf2 I have two buttons (one t
close the userform, the other to copy the data selected in the listbo
into a textbox (tb5) on uf1). This is where I am struggling.

I'm looking for the second button to capture the selections made i
lb1, copy these into tb5 (in the format ... John Smith; Jane Doe; Jo
Bloggs etc), and then close uf2 and return the user to uf1 with dat
populated. I'm not sure how to copy selected data from one userform t
the other
 
J

Jim Rech

I'd suggest that in second userform's module you have a sub like this run
from the button's click:

Private Sub CommandButton1_Click()
CopySelectedItems
Unload Me
End Sub

and in a standard module a routine like this to do the actual "copy" of the
selected items:

Sub CopySelectedItems()
Dim Counter As Integer
Dim LB As MSForms.ListBox
Set LB = UserForm2.ListBox1
For Counter = 0 To LB.ListCount - 1
If LB.Selected(Counter) Then
UserForm1.ListBox1.AddItem LB.List(Counter)
End If
Next
End Sub


--
Jim Rech
Excel MVP
|
| I have a userform (uf1) which contains a button which will display
| another userform (uf2) when selected.
|
| On uf2 I have a listbox which populates with with a number of colleague
| names when it opens. The listbox (lb1)is configured to allow selection
| of more than one name at a time. Also on uf2 I have two buttons (one to
| close the userform, the other to copy the data selected in the listbox
| into a textbox (tb5) on uf1). This is where I am struggling.
|
| I'm looking for the second button to capture the selections made in
| lb1, copy these into tb5 (in the format ... John Smith; Jane Doe; Joe
| Bloggs etc), and then close uf2 and return the user to uf1 with data
| populated. I'm not sure how to copy selected data from one userform to
| the other.
|
|
| --
| Alan T
|
|
| ------------------------------------------------------------------------
| Alan T's Profile:
http://www.excelforum.com/member.php?action=getinfo&userid=2068
| View this thread: http://www.excelforum.com/showthread.php?threadid=268420
|
 
Top