title: if error and vlookup in vba macros
body: <p>My task to write a formula which includes if, iferror and Vlookup </p>
  
  <p>I need to apply the formula till the end of last row which contains values .</p>
  
  <p>if vlookup throws NA , then the cell should be blank , othewise the value should be replaced with numerical Value "1"</p>
  
  <p>but when tried formula but it is giving error</p>
  
  <pre><code>Sub testt()
  
  Dim l As Long
  
  l = Sheets(1).Range("A1:A" &amp; Sheets(1).Cells(Sheets(1).Rows.Count, "A").End(xlUp).Row).Count
      With Sheets("Sheet1")
          .Range("d1").Formula = "=IF(iferror(vlookup(c2,$D:$D,1,false),""),"",1)"
          .Range("d1").AutoFill Destination:=Range("d1:d" &amp; l), Type:=xlFillDefault
  
      End With
  
  End Sub
  </code></pre>