title: How do I fix this compile error - Expected end of statement? Inputting a formula into a cell with VBA that passes a VBA variable into that formula
body: <p>I've got a variable that adds 3 to a number that a user inputs on a userform.  Then, I create a table with that many rows on another sheet.  Then, I want a cell on that sheet to count the cells that are in the table and tell the user.  I want to do this in VBA because this Sub generates a new sheet/table each time it's run so I can't just enter the formula in the cell and keep it there.</p>
  <pre><code>Dim Qnum as Integer 'Defined the integer
  Dim ws as Worksheet
  
  Set ws = Sheets(&quot;Test&quot;)
  Qnum = 3 + GenTest.txtNum 'adding three to the number of rows the user has requested
  
  with ws
  .Range(&quot;C1&quot;).Formula = &quot;=Counta(D4:D&quot; &amp; Qnum&quot;)&quot; 'This gives a compile error - expected end of statement
  </code></pre>
  <p>This is just the part of the code that's returning the error.  The rest of the code (not shown) creates a table from the A:D column with the amount of rows that the Qnum variable has.</p>
  <p>What am I missing here?</p>