Text box to list box population

likexl

New Member
Joined
May 7, 2011
Messages
18
Hi,

I want to know that : "Is it possible to populate a list box from one column in worksheet, as we start typing in the text box. As the letters are typed the list box should be updated with the most relevant match"

If it is possible, what is the basic approch to be started.

Excel vba, office 2007, win 7.

Thanks.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Hi all,

Thanks for reading this post.

I was confused regarding this matter. Thanks Gooooooo.. for directing me towards some tips.

I had arrived to the solution to dynamically update list box using text box typing.
I am posting this code for any one who find it useful. Any suggestion or improvements are invited.

code:

HTML:
Private Sub TextBox1_Change()

ListBox1.Clear

Application.Goto Reference:=Worksheets("sheet1").Range("a2")

Dim NumCounta As Long
NumCounta = Cells(Rows.Count, "A").End(xlUp).Row

Dim qry As String
    
    For i = NumCounta To 2 Step -1
    qry = TextBox1.Value
    If ActiveCell.Value Like qry & "*" Then
    With Me.ListBox1
    .AddItem ActiveCell.Value
    End With
    ActiveCell.Offset(1, 0).Select
    End If
    Next i

End Sub


I had first initialised list box with all items.

One question : If this loop is applied to large ranges will it affect speed. What to do to make execution fast.
 
Last edited:
Upvote 0
Solution
Hi all,

Thanks for reading this post.

I was confused regarding this matter. Thanks Gooooooo.. for directing me towards some tips.

I had arrived to the solution to dynamically update list box using text box typing.
I am posting this code for any one who find it useful. Any suggestion or improvements are invited.

code:

HTML:
Private Sub TextBox1_Change()

ListBox1.Clear

Application.Goto Reference:=Worksheets("sheet1").Range("a2")

Dim NumCounta As Long
NumCounta = Cells(Rows.Count, "A").End(xlUp).Row

Dim qry As String
    
    For i = NumCounta To 2 Step -1
    qry = TextBox1.Value
    If ActiveCell.Value Like qry & "*" Then
    With Me.ListBox1
    .AddItem ActiveCell.Value
    End With
    ActiveCell.Offset(1, 0).Select
    End If
    Next i

End Sub


I had first initialised list box with all items.

One question : If this loop is applied to large ranges will it affect speed. What to do to make execution fast.
Please note: Following is required with if.
HTML:
Else
    ActiveCell.Offset(1, 0).Select
 
Upvote 0

Forum statistics

Threads
1,215,343
Messages
6,124,405
Members
449,157
Latest member
mytux

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