title: Sum the values in excel with matching and changing criteria
body: <p>Referring to the linked picture below. Is there a way to sum values in &quot;size&quot; depending on two criteria: 1. the &quot;label&quot; is the same as &quot;class&quot;, 2. when the &quot;label&quot; changes (i.e. at row 3,8,...) it stops searching for criteria 1.</p>
  <p>For example,</p>
  <pre><code>D2 = A2+A3
  D3 = A4+A5+A6+A7+A8
  D4 = A9+A10
  D5 = A11+A12+A13+A14
  D6 = A15+A16
  D7 = A17+A18+A19+A20+A21.
  </code></pre>
  <p>The code I used was =sumifs(A:A,B:B,C2); however this formula does not give what I want and it outputs D2 = A2+A3+A9+A10+A17+A18+A19+A20+A21.</p>
  <p><img src="https://i.stack.imgur.com/sk4iJ.png" alt="enter image description here" /></p>