title: iteration of loop in formula vba
body: <p>I'm trying to sum a variable range of data starting at row 3. sortedRow is the row # of the end of the data. lColumn is the last column used as a number.</p>
  
  <p>I'm trying to sum the data in row 1, column H - lColumn.</p>
  
  <p>I need to have the formula calculate the sum of column G, then iterating on referenced column by the current iteration (which will be columns h through x)</p>
  
  <p>I've taken Scott Craner's advice and edited my code as </p>
  
  <pre><code>Dim lColumn As Long
  lColumn = ActiveSheet.Cells(3, Columns.Count).End(xlToLeft).Column
  sortedRow = Cells(Rows.Count, "D").End(xlUp).Row
  
  Dim i As Integer 'iterated column sum cell 
  For i = 8 To lColumn
  
      Cells(1, i).Value =Application.WorksheetFunction.SumIfs(Range(Cells(3,7), 
      Cells(sortedRow, 7)), Range(Cells(3, i), Cells(sortedRow, i)), 1)
  
  Next i
  </code></pre>
  
  <p>The cells are not being updated with their values though.
  It feels like I'm missing something really obvious with actually applying the number to the cell. I thought the above would do it.</p>
  
  <p>added lColumn declaration because of issue with the formula being applied
  added sortedRow declaration.</p>
  
  <p><a href="https://i.stack.imgur.com/c8sPW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/c8sPW.png" alt="basically this. But with variable column lengths and number of columns"></a></p>
  
  <p>basically this. But with variable column lengths and number of columns.
  It didn't matter for Column H that there was "#VALUE" in the volume column. So I assume it doesn't matter for the other columns.</p>
  
  <p>Any help would be appreciated!</p>