title: Application.Worksheetfunction Sumproduct issue
body: <p>I have an excel sheet and I am trying to use a countifs formula to count the number or records meeting multiple conditions, however in one of the columns there are multiple criterias so I used SUMPRODUCT together with the COUNTIFS function.</p>
  
  <p>I got it to work fine in the sheet but I have no idea on how to get it to work in VBA.</p>
  
  <p>This is what I tried:</p>
  
  <pre><code>Dim lastrow As Long
  lastrow = Sheet2.Cells(Sheet2.Rows.Count, "M").End(xlUp).Row
  FirstDate = Sheets("Sheet1").Range("C7")
  SecondDate = Sheets("Sheet1").Range("E7")
  
     Application.Worksheetfunction.Sumproduct(CountIfs(Sheet2.Range("E2:E" &amp; lastrow), "&gt;=" &amp; FirstDate, Sheet2.Range("E2:E" &amp; lastrow), "&lt;=" &amp; SecondDate, Sheet2.Range("P2:P" &amp; lastrow), {"John";"James";"Peter"}))
  </code></pre>
  
  <p>I keep getting an error when using the above formula. Can you please tell me what I'm doing wrong.</p>
  
  <p>Thanks in advance.</p>
  
  <p>EDIT: This is the formula I'm trying to mimic:</p>
  
  <p>=Sumproduct(CountIfs(Sheet2!E2:E1000000,">="&amp;Sheet1!C7,Sheet2!E2:E1000000,"&lt;="&amp;Sheet1!E7,Sheet2!E2:E1000000,{"John";"James";"Peter"}))</p>
  
  <p>I don't want VBA to insert this formula into the cell, I'd rather have it calculate the value and then insert the result into the chosen cell.</p>