title: Excel VBA SUMIFS on multiple range objects with a condition referencia a pivot table
body: <p>I'm trying to build a macro to create a table based on SUMIfs formula with 2 criteria.
  The first criteria Range takes values from a table without table format and the number of rows changes daily, so I use LastRow examples from the internet. and the criteria for this case is &quot;C&quot; for purchasing in Spanish</p>
  <p>the second criteria Range is another column from the same table without table formatting and criteria 2 comes from the value of a row within a pivot table</p>
  <pre><code>'Generar Formulas de a Partir de L (C= Montos de Compra)
      Range(&quot;L&quot; &amp; Rows.Count).End(xlUp).Offset(3).Select
      ActiveCell.FormulaR1C1 = &quot;C&quot;
      Range(&quot;L&quot; &amp; Rows.Count).End(xlUp).Offset(1).Select
  
  'Se aplica la formula de SUMIFS para dos condiciones, de Operación y tit
     Dim lRowJ As Long
     Dim lRowAA As Long
     Dim lRowV As Long
     Dim rngCriterio1 As Range
     Dim rngCriterio2 As Range
     Dim rngSuma As Range
  'Asignación de los rangos
     lRowJ = Range(&quot;J&quot; &amp; Rows.Count).End(xlUp).Row
     lRowAA = Range(&quot;AA&quot; &amp; Rows.Count).End(xlUp).Row
     lRowV = Range(&quot;V&quot; &amp; Rows.Count).End(xlUp).Row
     Set rngCriterio1 = Range(&quot;J2&quot; &amp; lRowJ)
     Set rngCriterio2 = Range(&quot;AA2&quot; &amp; lRowAA)
     Set rngSuma = Range(&quot;V2&quot; &amp; lRowV)
  'Uso de los rangos en la fórmula.
  Range(ActiveCell, ActiveCell) = WorksheetFunction.SumIfs _
      (rngSuma, rngCriterio1, &quot;C&quot;, rngCriterio2, &quot;=RC[-9]&quot;)
  'Liberación de los objetos.
    Set rngCriterio1 = Nothing
    Set rngCriterio2 = Nothing
    Set rngSuma = Nothing
  
  ' Se autocompleta con la formula
      
      Dim ultimaFila As Long
      ultimaFila = Range(&quot;C&quot; &amp; Rows.Count).End(xlUp).Row
      Selection.AutoFill Destination:=Range(ActiveCell.Address &amp; &quot;:L&quot; &amp; ultimaFila)
  </code></pre>
  <p>however, the result it throws is zero in each cell that is autocompleted, it does not even put the formula</p>