how would you have a listbox automaticly remove duplicates.
Printable View
how would you have a listbox automaticly remove duplicates.
Try this:
VB Code:
Private Sub RemoveDuplicates(list As ListBox) Dim i As Integer, x As Integer For i = 0 To list.ListCount - 1 For x = 0 To list.ListCount - 1 If i <> x Then If list.list(i) = list.list(x) Then list.RemoveItem (x) End If End If Next x Next i End Sub Private Sub Command1_Click() Call RemoveDuplicates(List1) End Sub
If the listbox is sorted you could do something like
For t=lstListBox.Listcount-1 to 1 step -1
if lstListBox.list(t)=lstListBox.list(t-1) then
lstListBox.RemoveItem(t)
End If
Next t