Filter List Box From TextBox

IoanZ

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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

mart37

Well-known Member
Joined
Aug 4, 2017
Messages
1,091
Office Version
  1. 2016
Platform
  1. Windows
If InStr(sTemp, Str) = 0 Then
 
Solution

Watch MrExcel Video

Forum statistics

Threads
1,130,172
Messages
5,640,580
Members
417,151
Latest member
ChickenTenderer

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
Top