After rereading of this thread with a cup of coffee it is my understanding of the modified task: the multi-selected items of ListBox1 have to be added into ListBox2.
And I guess that Listbox2 list shall be unique and sorted, because without it the example is present in VBA-help.
If so then example is attached. It’s UserForm1 code:
' Copy all the code into UserForm with ListBox1, Lisbox2 and CommandButton1
' Put some test items into ListBox1
Private Sub UserForm_Initialize()
ListBox1.List = Array("Item1", "Item2", "Item3", "Item4", "Item5")
End Sub
' Copy selected items of Listbox1 into Luistbox2
Private Sub CommandButton1_Click()
Lb1SelectedToLb2 ListBox1, ListBox2
End Sub
' Copy selected items of Lb1 into Lb2, make it unique, sort and place into Lb2
Sub Lb1SelectedToLb2(Lb1 As MSForms.ListBox, Lb2 As MSForms.ListBox)
Dim a(), i&, j&, s$
On Error Resume Next
With New Collection
' Sort unique items of Lb2
For j = 0 To Lb2.ListCount - 1
s = Trim(Lb2.List(j))
If IsEmpty(.Item(s)) Then
' Thanks to PGC01 for suggested fast sorting method for collection!
For i = 1 To .Count
If s < .Item(i) Then Exit For
Next
If i > .Count Then .Add s, s Else .Add s, s, Before:=i
End If
Next
' Add as unique the selected items of Lb1 into Lb2
For j = 0 To Lb1.ListCount - 1
If Lb1.Selected(j) Then
s = Trim(Lb1.List(j))
If IsEmpty(.Item(s)) Then
For i = 1 To .Count
If s < .Item(i) Then Exit For
Next
If i > .Count Then .Add s, s Else .Add s, s, Before:=i
End If
Lb1.Selected(j) = False
End If
Next
' Copy Collection items into array
ReDim a(1 To .Count)
For i = 1 To .Count
a(i) = .Item(i)
Next
End With
' Put unique sorting items into Lb2
Lb2.List = a()
End Sub
Vladimir