stirlingmw
Board Regular
- Joined
- Feb 18, 2013
- Messages
- 75
So i have been trying to get a Userform which transfers a selection from 2 listboxes into a single multicolumn listbox to work. With the help of this forum i have also been able to pass that data over to another "Master" Userform. What i am now struggling to do is 2 things.
1. When the command button on the "Master" Userform "Save" is pressed the data from Listbox1 should be passed across to worksheet "Master" column "C". I have managed to do this of sorts, but only the first column of data out of 2 is transferred to the relevant cell. How do I pass both columns to the same Cell.
2. My 2nd Userform enables me to generate the data in listbox1 by passing selected data from 2 listboxes "listRole" and "listName" into a third "listResponsible" as a single line of data at a time and removing the selected data from listRole and listName so the same data cannot be selected more than once. This Userform is opened from a command button on my "Master" Userform above listbox1. If data is already present in listbox1 i would like this data to appear in listResponsible and the relevant data from Role and Name to be removed from listRole and listName.
Code i am using is
and the code to pass the multicolumn data from listbox2 to listbox1 on "Master" Userform
Thanks
Steve
1. When the command button on the "Master" Userform "Save" is pressed the data from Listbox1 should be passed across to worksheet "Master" column "C". I have managed to do this of sorts, but only the first column of data out of 2 is transferred to the relevant cell. How do I pass both columns to the same Cell.
2. My 2nd Userform enables me to generate the data in listbox1 by passing selected data from 2 listboxes "listRole" and "listName" into a third "listResponsible" as a single line of data at a time and removing the selected data from listRole and listName so the same data cannot be selected more than once. This Userform is opened from a command button on my "Master" Userform above listbox1. If data is already present in listbox1 i would like this data to appear in listResponsible and the relevant data from Role and Name to be removed from listRole and listName.
Code i am using is
Code:
'Move selected data into a single listbox
Private Sub BTN_MoveSelectedRight_Click()
Dim lb1 As MSForms.ListBox
Dim lb2 As MSForms.ListBox
Dim lb3 As MSForms.ListBox
Set lb1 = Me.ListRole
Set lb2 = Me.ListName
Set lb3 = Me.ListBox2
If lb1.ListIndex >= 0 And lb2.ListIndex >= 0 Then
lb3.AddItem lb1.Value
lb3.List(lb3.ListCount - 1, 1) = lb2.Value
' lb1.RemoveItem lb1.ListIndex
lb2.RemoveItem lb2.ListIndex
lb1.ListIndex = -1
lb2.ListIndex = -1
End If
End Sub
and the code to pass the multicolumn data from listbox2 to listbox1 on "Master" Userform
Code:
Private Sub CmdSave_Click()
For i = 0 To Me.ListBox2.ListCount - 1
filled = False
For j = 0 To Listbox1.ListBox2.ColumnCount - 1
If Listbox1.ListBox2.List(i, j) <> "" Then
filled = True
Exit For
End If
Next
If filled Then
Master.Listbox1.AddItem ListBox2.List(i, 0)
Master.Listbox1.List(Master.Listbox1.ListCount - 1, 0) = Me.ListBox2.List(i, 0)
Master.Listbox1.List(Master.Listbox1.ListCount - 1, 1) = Me.ListBox2.List(i, 1)
End If
Next
Unload Me
End Sub
Steve
Last edited: