title: Use .Formula to Sum a Changing Range of Cells
body: <p>I am trying to fill out a table by summing the first "x" number of values then the next "x" number of values.</p>
  
  <p>Essentially this:
  =SUM(Ax:Ay) where x and y are the row numbers</p>
  
  <pre><code>Sheets(1).Range("B"+i).Formula = "=SUM(A" &amp; x &amp; ":A" &amp; y &amp; ")"
  </code></pre>
  
  <p>Here is what my actual code looks like:</p>
  
  <pre><code>Private Sub ScrollBar1_Change()
  
  Application.ScreenUpdating = False
  
  Dim slider_val As Long
  Dim output_tbl As ListObject
  Dim data_tbl As ListObject
  Dim i As Long
  Dim j As Long
  Dim start As Long
  Dim finish As Long
  
  Set data_tbl = Sheets("Data").ListObjects("DataTable")
  Set output_tbl = Sheets("Slider").ListObjects("OutputTable")
  slider_val = Sheets("Slider").Range("A5").Value
  
  start = 2
  
      For i = 1 To 12
  
          finish = start + slider_val
  
          Sheets("Slider").Range("B" &amp; j).Formula = "=SUM(Data!K" &amp; start &amp; ":K" &amp; finish &amp; ")"
  
          j = j + 1
          start = finish + 1
  
      Next i
  
  Application.ScreenUpdating = True
  End Sub
  </code></pre>
  
  <p>I get the error "Application-defined or object-defined error" when I try to run this code. </p>