title: VBA to put SUMIFS in a cell
body: <p>I wrote code to put SUMIFs in a cell based on sheet name. newFileName and oldFileName are declared variables used as sheet names.</p>
  <pre><code>Sheets(newFileName).Select
  Range(&quot;C2&quot;).Formula = WorksheetFunction.SumIfs(Sheets(oldFileName).Range(&quot;$G:$G&quot;), Sheets(oldFileName).Range(&quot;F:F&quot;), Range(&quot;B2&quot;))
  </code></pre>
  <p>This works!</p>
  <p>However, I want to put the SUMIFS formula in cell C2</p>
  <pre><code>Sheets(newFileName).Select
  Range(&quot;C2&quot;).Formula = &quot;=SumIfs(Sheets(oldFileName).Range(&quot;$G:G&quot;), Sheets(oldFileName).Range(&quot;F:F&quot;), Range(&quot;B2&quot;))&quot;
  </code></pre>
  <p>This gives a compile error. Any ideas how to make it work?</p>