-
Unique items in ListBox
Hi guys
I'm trying to add items to a ListBox through a TextBox on condition that the items in the ListBox are unique ..
In other words,If I tried to add a new item through the textbox a message appeared to tell me that "The item is listed in the listbox"
-
Perhaps
[VBA]Private Sub CommandButton1_Click()
Dim newItem As String
Dim listPointer As Long
newItem = TextBox1.Text
With ListBox1
For listPointer = 0 To .ListCount - 1
If LCase(newItem) = LCase(.List(listPointer)) Then
MsgBox newItem & " is already in the list."
Exit Sub
ElseIf LCase(newItem) < LCase(.List(listPointer)) Then
Exit For
End If
Next listPointer
.AddItem newItem, listPointer
TextBox1.Text = vbNullString
End With
End Sub[/VBA]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules