View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
cht13er cht13er is offline
external usenet poster
 
Posts: 141
Default Selection based on partial input

On Mar 15, 6:46 am, affordsol
wrote:
Hi to all,

In an Excel workbook, sheet1 has a list of the customer names :
col1=idx and col2=name

I need to build up a user form with
one Textbox
one Listbox
one Button (Exit)

I need to enable the user to input the beginning of a name in the textbox,
and, as each new typed character comes in, I want the listbox to display (in
full) all of the names on sheet1 beginning with the actual content of the
textbox to be listed in the listbox.
The final selection is then done by a double click on the choosen name of
the listbox.

How can I code that in vba ??

Thanks by advance for your help,
Herve+
--
Herve Hanuisehttp://www.affordsol.be


Here you go:

Private Sub TextBox1_Change()

'Clear previous entries
UserForm1.ListBox1.Clear

Dim strPartial As String
strPartial = UserForm1.TextBox1.Text

Sheets("Sheetname").Activate
Cells(1, 1).Select

Do Until ActiveCell = ""
If Left(ActiveCell, Len(strPartial)) = strPartial Then
UserForm1.ListBox1.AddItem (ActiveCell)
End If
ActiveCell.Offset(1, 0).Select
Loop

End Sub


Works for me :)

Chris