Hello!

I created an excel macro that looks up last names in a table on another worksheet using vlookup. If a last name is found, the number 15 is placed in a column on the first worksheet. If the name is not found (which is common), I want a 4 to be placed there instead. I tried to deal with this using an error handler, but instead of returning 4, the handler just puts a 15 next to every term whether it appears in the vlookup range or not! Did I enter something incorrectly? I'm a VBA beginner so I feel like I'm missing something really obvious.


Code I'm Using:

Sub LookUpAndCopy()

On Error GoTo ErrorHandler:

Dim LastName As Range
Dim b As Long

For b = 3 To 12
    Set LastName = Sheets("Testing").Range("B" & b)
    Sal = Application.WorksheetFunction.VLookup(LastName, Sheets("Admin").Range("AF3:AG12"), 2, False)
    Sheets("Testing").Range("K" & b).Value = Sal
Next b

ErrorHandler:
    If Err.Number = 1004 Then
        Sheets("Testing").Range("K" & b).Value = "4"
        Resume Next
    End If

End Sub