VBA vlookup enter data into one textbox have another auto fill

Joined
Apr 17, 2012
Messages
1
Reaction score
0
Hi

I have been working on this for a couple of days and googling everything i can think of - no success.

I have a form in excel that i need to enter the Employee No - 5 digits in length (txtEmployeeNo) in one text box then have a second show their Surname (txtSurname). It sounds easy enough and i have tried a few variations but i can't seem to get any of the codes i have found to work for me.

I'm trying to get the txtSurname to look up a worksheet (EmployeeDetails) in the same workbook with the employee numbers are in column A in order and the surnames are in column B.

I keep getting a 1004 error and the 3rd line highlights in yellow

Private Sub txtEmployeeNo_Change()
If txtEmployeeNo <> "" Then
txtSurname.Value = Excel.WorksheetFunction.VLookup(txtEmployeeNo.Value, Sheets("EmployeeDetails").Range("A1:C17"), 2, False)
End If
End Sub

thank-you for any help you all can provide.
bronte
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top