Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.programming
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"