RBartonSWW
New Member
- Joined
- Nov 18, 2005
- Messages
- 38
Could some people please test this code, basicaly it is meant to copy data from a spreadsheet to a userform.
When you press a button on the userform it looks throught the spreadsheet for the Account Number entered in the 'tbAcc' text box, and if it finds it then it will copy the data from the ofset cell into the 'tbName' text box.
It works, but it seems to (atleast for me) insert a character which is not in the spreadsheet. Does it do this for anybody else?!
When you press a button on the userform it looks throught the spreadsheet for the Account Number entered in the 'tbAcc' text box, and if it finds it then it will copy the data from the ofset cell into the 'tbName' text box.
It works, but it seems to (atleast for me) insert a character which is not in the spreadsheet. Does it do this for anybody else?!
Code:
Private Sub cmdSearch_Click()
Dim firstCell, nextCell, stringToFind As String
stringToFind = tbAcc.Value
Set firstCell = Cells.Find(what:=stringToFind, lookat:=xlWhole, _
searchdirection:=xlPrevious)
If firstCell Is Nothing Then
Dim msg As String
msg = "Claim not found. Do you want to create a new one?"
If MsgBox(msg, vbQuestion + vbYesNo, "Claim not found") = vbNo Then Exit Sub
frmNew.Show
Else
nextCell = _
Cells.FindNext(after:=Range(firstCell.Address)).Address
Range(firstCell.Address).Select
Selection.Offset(0, 1).Select
ActiveCell.Copy
tbName.Paste
End If
End Sub