Reputation: 63
How do you inject the iferror function on this code?
For d = 2 To lastrowx2
Worksheets("Educational Service Report").Cells(d, 16).Value = Application.WorksheetFunction.VLookup( _
Worksheets("Educational Service Report").Cells(d, 15).Value, _
Worksheets("Educational Service Report").Range("X:Y"), 2, 0)
Next
I just want a null value cells (d, 16) if it is an error.
Upvotes: 1
Views: 100
Reputation: 7735
Something like below would do that for you, a nested application function:
For d = 2 To lastrowx2
Worksheets("Educational Service Report").Cells(d, 16).Value = Application.IfError( _
Application.VLookup(Worksheets("Educational Service Report").Cells(d, 15).Value, _
Worksheets("Educational Service Report").Range("X:Y"), 2, 0), "")
Next d
Upvotes: 2
Reputation: 43585
Add before the row with Next
:
If IsError(Worksheets("Educational Service Report").Cells(d, 16)) Then
Worksheets("Educational Service Report").Cells(d, 16) = ""
End If
Upvotes: 0