Excel VBA Dynamic Filter TextBox from ListBox Values

EverLearner

New Member
Joined
Apr 17, 2020
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I have populated a column range cells into a UserForm ListBox (below is the code bulk). Now I want to create a TextBox in the same Form to dynamically filter the contents of that ListBox as I type my entry. How can I utilize the AutoFilter method to call the ListBox content? Thanks for your help.

Set rSource = Sheets("Property").Range(Range("B5"), Range("B5").End(xlDown))

ListBox1.List = rSource.Cells.Value
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
welcome to the forum

Remove the above lines
Set rSource = Sheets("Property").Range(Range("B5"), Range("B5").End(xlDown))
ListBox1.List = rSource.Cells.Value


Instead the ListBox is filled dynamically by code below

This works for me, where TextBox1 is the textbox and ListBox1 is the listbox

Rich (BB code):
Private Sub TextBox1_Change()
    Dim ws As Worksheet, rng As Range, cel As Range
    ListBox1.Clear
    Set ws = Sheets("Property")
    Set rng = ws.Range("$B$4", ws.Range("$B$4").End(xlDown))
    rng.AutoFilter Field:=1, Criteria1:="*" & TextBox1.Text & "*"
    
    On Error GoTo TheEnd
    Set rng = rng.Offset(1).Resize(rng.Rows.Count - 1).SpecialCells(xlCellTypeVisible)
    On Error GoTo 0
    For Each cel In rng
        ListBox1.AddItem cel
    Next
TheEnd:
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,587
Messages
6,120,405
Members
448,958
Latest member
Hat4Life

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