msquared99
Member
I have a UserForm, I enter a ID number into a TextBox called tbCOID. I am trying to use the Find method to look for the value in tbCOID and have it populate other TextBoxes. The data I'm trying to retrieve is stored in Sheet3 of the Workbook that has the macro.
The code only returns the values in row 2. It is as if that is the only row the code looks at.
Any suggestions?
Here is the code:
[pre]
[/pre]
The code only returns the values in row 2. It is as if that is the only row the code looks at.
Any suggestions?
Here is the code:
[pre]
Code:
Private Sub tbCOID_Exit(ByVal Cancel As MSForms.ReturnBoolean)
'Looks for COID in Sheet3 and auto populates several textboxes
Dim rng As Range, SearchResult As Range
Dim cel As String
Me.tbCOID = Format(Me.tbCOID, "0000")
Set rng = Worksheets("Sheet3").Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row)
cel = tbCOID.Value
Set SearchResult = rng.Find(what:=cel, LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByRows, searchdirection:=xlNext, MatchCase:=False)
If Not SearchResult Is Nothing Then
'Found it!
'Populate TextBoxes with found values from Sheet3
frmSales.tbName.Value = SearchResult.Offset(0, 1).Value
frmSales.tbRep.Value = SearchResult.Offset(0, 2).Value
frmSales.tbEECount.Value = SearchResult.Offset(0, 5).Value
frmSales.tbHourlyEE.Value = SearchResult.Offset(0, 6).Value
frmSales.tbInput.Value = SearchResult.Offset(0, 3).Value
tbHourlyPer.Value = Format(tbHourlyEE.Value / tbEECount.Value, "0.0%")
Else
'Did not find it.
MsgBox "COID Not Found!"
End If
End Sub