title: Excel VBA formula with variables
body: <p>I would like to generate a formula in my code, say for example,</p>
  
  <pre><code> Range("L2:L17).Formula="=SUMIF($A$2:$A$17,A2,G2:G17)"
  </code></pre>
  
  <p>Except, I would like L, G, and A to be variables that are decided by some other factors earlier in the macro. Similarly, I would also like  2, and 17 to be replaced by two variables, whose specific values are determined earlier in the code.</p>
  
  <p>So something like</p>
  
  <pre><code>Range("var1 j: var1 k).Formula="=SUMIF($ var2 $ j : $ var2 $ k, var2 j, var3 j : var3 k)"
  </code></pre>
  
  <p>I guess I could convert these variables to string and just to a string concatenate but I am not able to do it just yet. Everything I try gives errors.</p>
  
  <pre><code>Range(foldtot_add &amp; "2:"&amp; foldtot_add &amp; FinalRow).Formula="=SUMIF("$"&amp;FolderId_add &amp; "$2:" &amp; "$"&amp; FolderId_add &amp; FinalRow, FolderId_add &amp;" 2", daycountcol2 &amp; "2 :" &amp; daycountcol2 &amp; FinalRow)"
  </code></pre>
  
  <p>Where foldtot_add, FolderId_add, and daycountcol2 are names of my columns and FinalRow is the name of a row.</p>