Name look up

G

Greg B

I have put the code below I use to look up a name but the problem I am
having is how do I get it to search for the next name in the list?

Private Sub TextBox1_AfterUpdate()
Sheets("customer").Select

Dim ans

On Error Resume Next
ans = Application.Match(CLng(TextBox1.Text), Range("A1:A100"), 0)
If Not IsError(ans) Then
TextBox2.Text = Application.Index(Range("B1:B100"), ans)
TextBox3.Text = Application.Index(Range("C1:C100"), ans)
TextBox4.Text = Application.Index(Range("D1:D100"), ans)
TextBox5.Text = Application.Index(Range("E1:E100"), ans)
TextBox6.Text = Application.Index(Range("F1:F100"), ans)
TextBox7.Text = Application.Index(Range("G1:G100"), ans)
TextBox8.Text = Application.Index(Range("H1:H100"), ans)
TextBox9.Text = Application.Index(Range("I1:I100"), ans)
Else
MsgBox "Invalid code"
End If
On Error GoTo 0
End Sub
Thanks

Greg
 
G

Guest

Private Sub TextBox1_AfterUpdate()
Static ans As Long
Dim col As Long
ans = ans + 1
With Sheets("customer")
For col = 1 To 0
Controls("TextBox" & col) = .Cells(ans, col).Value
Next
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Please help with code? 2
Look up 4
Error control? 2
Auto look up 1
Help with code please? 6
Help with code please 1
Force proper case on user form text box 7
Referencing a UserForm 2

Top