title: Type mismatch when setting a formula into a cell with VBA
body: <pre><code>Worksheets("sheet2").Range("C2").Formula = "=AVERAGEIFS(Sheet1!E:E,Sheet1!A:A," &gt;= "&amp;A2,Sheet1!A:A," &lt; "&amp;B2)"
  </code></pre>
  
  <p>I have run the above code in Excel 2007 and I'm getting a </p>
  
  <blockquote>
    <p>run time error 13 type mismatch</p>
  </blockquote>
  
  <p>The above code is used to do average operation from sheet 1 and enter in sheet 2. I request some help in correcting the error.</p>