Hello to everyone.
Please help me.
I have a Userform which contains a Listbox and a Textbox
The ListBox in populated with few items when the userform it's initialized.
Private Sub UserForm_Initialize()
With Me.ListBox1
.AddItem "Apple"
.AddItem "Orange"
.AddItem "Other"
End with
End Sub
With this code when the TextBox is fill and I press Enter the item which was written in TextBox it's removed from in ListBox
Private Sub TextBox1_AfterUpdate()
Dim i As Long
Dim n As Long
Dim Str As String
Dim sTemp As String
Str = LCase(Me.TextBox1.text)
n = Me.ListBox1.ListCount
For i = n - 1 To 0 Step -1
sTemp = LCase(Me.ListBox1.List(i))
If InStr(sTemp, Str) > 0 Then
ListBox1.RemoveItem (i)
End If
Next i
End Sub
Question: I want to know which is vba code to keep in the listbox the items which was written in TextBox and remove the others
Thank's
Please help me.
I have a Userform which contains a Listbox and a Textbox
The ListBox in populated with few items when the userform it's initialized.
Private Sub UserForm_Initialize()
With Me.ListBox1
.AddItem "Apple"
.AddItem "Orange"
.AddItem "Other"
End with
End Sub
With this code when the TextBox is fill and I press Enter the item which was written in TextBox it's removed from in ListBox
Private Sub TextBox1_AfterUpdate()
Dim i As Long
Dim n As Long
Dim Str As String
Dim sTemp As String
Str = LCase(Me.TextBox1.text)
n = Me.ListBox1.ListCount
For i = n - 1 To 0 Step -1
sTemp = LCase(Me.ListBox1.List(i))
If InStr(sTemp, Str) > 0 Then
ListBox1.RemoveItem (i)
End If
Next i
End Sub
Question: I want to know which is vba code to keep in the listbox the items which was written in TextBox and remove the others
Thank's