Locate In listbox

sadath

Active Member
Joined
Oct 10, 2004
Messages
262
Office Version
  1. 365
Platform
  1. Windows
I have a listbox in a userform with column count is 2. The first column with employee no and second column with Name.
I have a textbox in the same userform.
when a start entering a text in textbox it should serch in listbox name field and locate the nearest match.
eg. in listbox i have in first row 242 Will Smith.
if I enter either Will or Smith in the text box it should locate in first row.

thanks
anyones help appreciated
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Which takes precedence, first name or last name? For example you could have:

001 Douglas James
002 James Douglas
 
Upvote 0
let it be first name..
I'm waiting for your post...
 
Upvote 0
Try this:

Code:
Private Sub TextBox1_Change()
    Dim r As Long
    For r = 0 To ListBox1.ListCount - 1
        If Left(ListBox1.Column(1, r), Len(TextBox1.Text)) = TextBox1.Text Then
            ListBox1.SetFocus
            ListBox1.ListIndex = r
            TextBox1.SetFocus
            TextBox1.SelStart = Len(TextBox1.Text) + 1
            Exit For
        End If
    Next r
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,332
Messages
6,124,314
Members
449,153
Latest member
JazzSingerNL

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