Fast way to remove all duplicates (dupes) in a ListBox
This method removes all duplicates in a listbox, regardless if sorting is turned on or not.
AND it's fast, short and simple
(no double loops like in some other submissions).
It's also case-insensitive.
Inputs
Call by using: RemoveDupes MyListBox
(where MyListBox is the listbox that will
be cleaned of all duplicates.)
Assumes
Call by using: RemoveDupes MyListBox
(where MyListBox is the listbox that will
be cleaned of all duplicates.)
Rate Fast way to remove all duplicates (dupes) in a ListBox
(5(5 Vote))
Private Sub RemoveDupes(lst As ListBox)
Dim iPos As Integer
iPos=0
'-- if listbox empty then exit..
If lst.ListCount < 1 Then Exit Sub
Do While iPos < lst.ListCount
lst.Text = lst.List(iPos)
'-- check if text already exists..
If lst.ListIndex <> iPos Then
'-- if so, remove it and keep iPos..
lst.RemoveItem iPos
Else
'-- if not, increase iPos..
iPos = iPos + 1
End If
Loop
'-- used to unselect the last selected line..
lst.Text = "~~~^^~~~"
End Sub
Fast way to remove all duplicates (dupes) in a ListBox Comments
No comments yet — be the first to post one!
Post a Comment