Sub Button4 Click()
On Error GoTo Msg
Dim x As Integer, erow As Integer, lrow As Integer
erow = Sheets("XYZ").Range("D" & Rows.Count).End(xlUp).Row
lrow=Sheets("ABC").Range("A" & Rows.Count).End(xlUp).Row
For x = 2 To erow
Sheets("XYZ").Range ("G" & x) = WorksheetFunction. VLookup (Sheets("XYZ").Range("D" & x), Sheets("ABC").Range("A2:C" & erow), 2, 0)
Next x
Exit Sub
Msg: (Sheets("XYZ").Range("G" & x) = "N/A"
Resume Next
End Sub
Whenever trying to run the above code it's directly getting me to the MSG and returning value as N/A considered as an error.