Sub Sort_MasterAgent()
Dim vaItems As Variant
Dim i As Long, j As Long
Dim vTemp As Variant
'Put the items in a variant array
vaItems = frm_MENU.lbox_MASTERAGENT.List
For i = LBound(vaItems, 1) To UBound(vaItems, 1) - 1
For j = i + 1 To UBound(vaItems, 1)
If vaItems(j, 0) = vaItems(i, 0) Then
End If
Next j
Next i
Sub aTest()
Dim i As Long, j As Long
Dim nodupes As New Collection
Dim Swap1, Swap2, Item
With frm_MENU.lbox_MASTERAGENT
For i = 0 To .ListCount - 1
' The next statement ignores the error caused
' by attempting to add a duplicate key to the collection.
' The duplicate is not added - which is just what we want!
On Error Resume Next
nodupes.Add .List(i), CStr(.List(i))
Next i
' Resume normal error handling
On Error GoTo 0
'Clear the listbox
.Clear
'Sort the collection (optional)
For i = 1 To nodupes.Count - 1
For j = i + 1 To nodupes.Count
If nodupes(i) > nodupes(j) Then
Swap1 = nodupes(i)
Swap2 = nodupes(j)
nodupes.Add Swap1, before:=j
nodupes.Add Swap2, before:=i
nodupes.Remove i + 1
nodupes.Remove j + 1
End If
Next j
Next i
' Add the sorted and non-duplicated items to the ListBox
For Each Item In nodupes
.AddItem Item
Next Item
End With
' Show the UserForm
frm_MENU.Show
End Sub
Thanks a lot for your help