Private Sub Text1_Change()
If (Object exists In listbox Or an Object that begins With a certain letter/letters exists) Then
If text1.text = "first few letters of the object" Then
text1.text = ""
Basically, this should stop the user from entering a piece of data twice because it they try to write it in the textbox if will automatically clear. Please imagine that there is only one object avaliable to enter. I will duplicate the code for the other avaliable items... it will be easier for me to understand later.
ListIndex = 0
Do Until ListIndex = List2.ListCount
'With this index, loop through all of the elements of the listbox in reverse order,
'removing any element that has the same text as this one.
TextToMatch = List2.List(ListIndex) 'Text of this item to check duplicates for
For LV = List2.ListCount - 1 To ListIndex + 1 Step -1 'loop through remaining items to check for duplicates.
'Notice: LB.ListCount -1 is the index of the last item in the listbox.
'LBIndex + 1 is the item immediately after the one that we are checking duplicates on.
If List2.List(LV) = TextToMatch Then
'We've found a duplicate! Delete it and then count it.
NumofDuplicates = NumofDuplicates + 1
'Go to the next item: all duplicates of this have been found.
ListIndex = ListIndex + 1