title: Excel VBA - Sum between two values
body: <p>I have a report where I'm trying to get the sum of a dynamic number of rows in order to produce a subtotal.</p>
  
  <pre><code>If Cells(s, 1).Value = "start" Then
     If Cells(r, 1).Value = "subtotal" Then
      'Set the Monthly Subtotal Formulas
       Cells(r, 44) = "=SUM(AR" &amp; Trim(Str(s)) &amp; ":AR" &amp; Trim(Str(r - 1)) &amp; ")"
       Cells(r, 46) = "=SUM(AT" &amp; Trim(Str(s)) &amp; ":AT" &amp; Trim(Str(r - 1)) &amp; ")"
      'Set the Weekly Subtotal Formulas
       Cells(r, 48) = "=SUM(AV" &amp; Trim(Str(s)) &amp; ":AV" &amp; Trim(Str(r - 1)) &amp; ")"
       Cells(r, 52) = "=SUM(AZ" &amp; Trim(Str(s)) &amp; ":AZ" &amp; Trim(Str(r - 1)) &amp; ")"
       'Set the Daily Subtotal Formulas
       Cells(r, 54) = "=SUM(BB" &amp; Trim(Str(s)) &amp; ":BB" &amp; Trim(Str(r - 1)) &amp; ")"
       Cells(r, 56) = "=SUM(BD" &amp; Trim(Str(s)) &amp; ":BD" &amp; Trim(Str(r - 1)) &amp; ")"
       'Set the Hourly Formulas
       Cells(r, 60) = "=SUM(BH" &amp; Trim(Str(s)) &amp; ":BH" &amp; Trim(Str(r - 1)) &amp; ")"
       Cells(r, 62) = "=SUM(BJ" &amp; Trim(Str(s)) &amp; ":BJ" &amp; Trim(Str(r - 1)) &amp; ")"
       Cells(r, 1) = ""
      End If
      Cells(s, 1) = ""
  End If
  </code></pre>
  
  <p>Basically, each work group is within the cell values "start" and "subtotal".
  How can I find the 's' or row number and use that in the formula?</p>