title: Insert formula with Variable VBA
body: <p>I'm trying to insert a formula in the Column C of Sheet2. The row number however depends on the value of pasterow. The range in the formula should be G[lastrow]:NS[lastrow] with lastrow pertaining to the last row of Sheet1. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>Sub try()
  
  With Sheets("Sheet2")
  
  pasterow = .Cells(.rows.Count, "B").End(xlUp).Offset(1, 0).Row
  
  With Sheets("Sheet1")
      lastRow = ActiveWorkbook.Worksheets("Sheet1").Range("F" &amp; .rows.Count).End(xlUp).Row
  
      ActiveWorkbook.Worksheets("Sheet2").Range("C" &amp; pasterow).formula = _
      "=COUNTIF(Sheet1!G &amp; lastRow &amp; :NS &amp; lastRow &amp; , ""VL"" )"
  
  End With
  End With
  
  End Sub
  </code></pre>
  
  <p>I'll really appreciate if someone could point out what's wrong with my code. Thanks!</p>