I am building a Userform which contains two ListBoxes such that the user can select options from ListBox1 and add them to ListBox2 or alternatively remove options from ListBox2
What I am struggling with is how can I prevent the duplicates from being added to the ListBox2? Essentially, I want to build in a function (?) which checks if an option is already included in ListBox2
Private Sub CommandButton3_Click()
'### Adds Items from ListBox1 to ListBox2
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then ListBox2.AddItem ListBox1.List(i)
Next i
ListBox1.Selected
End Sub
Private Sub CommandButton4_Click()
'### Removes Items from ListBox2
Dim counter As Integer
counter = 0
For i = 0 To ListBox2.ListCount - 1
If ListBox2.Selected(i - counter) Then
ListBox2.RemoveItem (i - counter)
counter = counter + 1
End If
Next i
End Sub