Welcome to the Forum Nicole17!
The code Resume Next causes execution to resume at the line of code following the one that caused the error. In your case, that line is the assignment of Sal to the Kb cell. So when you resume after the error, that line of code wipes out the value that was put there by your error handler.
To fix it, have your error handler update Sal instead of putting the value in the cell.
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
Sal = 4
Resume Next
End If
End Sub
I have made the minimal changes necessary to get your code to work. Here is another suggestion. Putting a Resume Next in an error handler results in what we old timers call "spaghetti code." Looking at the code you can't be sure where execution is going after that Resume Next (an experienced VBA programmer will know exactly which lines of code can raise a 1004 error, but it's better to be obvious). Here is another way to do this. This way you know exactly where the code is flowing under what conditions.
Sub LookUpAndCopy()
On Error Resume Next
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)
If Err.Number = 1004 Then
Sal = 4
Err.Clear
End If
Sheets("Testing").Range("K" & b).Value = Sal
Next b
End Sub
Bookmarks