ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Name look up (https://www.excelbanter.com/excel-programming/329441-name-look-up.html)

Greg B[_5_]

Name look up
 
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



Patrick Molloy[_2_]

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





All times are GMT +1. The time now is 06:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com