title: Run-time Error 1004 with Vlookup
body: <p>I want to create the below formula in Excel using VBA:</p>
  
  <pre><code>=IF(ISERROR(VLOOKUP($F4,'17402'!$B:$BD,'17402'!AS$50,0))=TRUE,"",(VLOOKUP($F4,'17402'!$B:$BD,'17402'!AS$50,0)))
  </code></pre>
  
  <p>This is my code:</p>
  
  <pre><code>Dim wsFormula          As String
  wsFormula = "=IF(ISERROR(VLOOKUP($F4," &amp; "" '"" var_SN &amp; ""'!"" &amp; "$B:$BD," &amp; ""'"" &amp; var_SN &amp; ""'!"" &amp; "AS$50,0))=TRUE,0,(VLOOKUP($F4," &amp; ""'"" var_SN &amp; ""'!"" &amp; "$B:$BD," &amp; ""'"" var_SN &amp; ""'!"" &amp; "AS$50,0)))"
  ActiveCell.Formula = wsFormula
  </code></pre>
  
  <p>Where “var_SN” is “17402”. I receive a Run-time error 1004, Application-defined or Object Define error error, so I wonder if the variable is the problem. I read about double stacking the quotes around ' and ! but that doesn't help.</p>
  
  <p>I also wonder if the lookup value $F2 will become a problem for me as the row reference changes each time I run the macro. For instance, if I am in row 4, I do not want this code writing a formula that would reference cell F1 as the lookup value. Thanks much.</p>