Excel 2013 VBA Doubt

2

I have this bit of code:

  Range("F8").Select

  For Each m In Range(Range("C8"), Range("C" & rows.Count).End(xlUp))

     If ActiveCell.Offset(0, 0) <> " " Then
        ActiveCell.Offset(0, 7) = Application.vlookup(ActiveCell, Sheets("Chargeback code-Pursuit").Range("A2:B20000"), 2, False)
        ActiveCell.Offset(1, 0).Select
     End If

  Next

And when doing this appears the desired data, but qd cell c8 is empty the field that is filling with vlookup is appearing as # N / A.

How do I make cells that contain # N / A become blank cells?

Below is the example of # N / A

Thanks for the help.

    
asked by anonymous 14.02.2018 / 18:22

1 answer

2

You can add the formula IFERROR :

ActiveCell.Offset(0, 7) = Application.iferror(Application.vlookup(ActiveCell, Sheets("Chargeback code-Pursuit").Range("A2:B20000"), 2, False),"")

o

ActiveCell.Offset(0, 7) = Application.vlookup(ActiveCell, Sheets("Chargeback code-Pursuit").Range("A2:B20000"), 2, False)
If IsError(ActiveCell.Offset(0, 7)) Then ActiveCell.Offset(0, 7) = ""
    
14.02.2018 / 19:46