Question : Vlookup "#N/A" error

I am getting a "#N/A" error while the vlookup not getting the reference value. I want to replace "#N/A" with "-".

I know there is a function for this. =if(d12="", "-", vlookup())

But I need to use this in a VBA module as below.

Windows("Book1.xls").Activate
    Range("G7").Select
    ActiveCell.FormulaR1C1 = _
        "=VLOOKUP(RC[-4],Book2.xls!R2C1:R32C8,8,0)"
    Selection.AutoFill Destination:=Range("G7:G14"), Type:=xlFillDefault

I need Experts help on this. Thank you.

Answer : Vlookup "#N/A" error

This will automatically populate your range in one go. You need not to go for selection autofill post that and i designed this macro basis of your existing data..and in it its b column..so the macro will become...

Saurabh...

1:
2:
3:
Windows("Book1.xls").Activate
Range("b2:b" & Cells(65536, "A").End(xlUp).Row).Select
Selection.Formula = "=IF(ISNA(VLOOKUP(A2,Sheet2!A:B,2,0)),""-"",VLOOKUP(A2,Sheet2!A:B,2,0))"
Open in New Window Select All
Random Solutions  
 
programming4us programming4us