Filter List Box From TextBox

IoanZ

Board Regular
Joined
Mar 2, 2018
Messages
51
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
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,215,884
Messages
6,127,564
Members
449,385
Latest member
KMGLarson

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top