Thread: Name look up
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Patrick Molloy[_2_] Patrick Molloy[_2_] is offline
external usenet poster
 
Posts: 1,298
Default Name look up

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

"Greg B" wrote:

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