title: Subtract an amount from a cell until it reaches 0, then move and subtract from the next amount
body: <p>Can you please assist me with the below?  The objective of my excel project is that each   time each time B is found in column A is minus the quantities of A till the quantity is reached.</p>
  
  <p>Only values with A is where the quantities will be subtracted from. 
  The next time it finds the next B , it will check any above A’s with remaining quantity and so. </p>
  
  <p><a href="https://i.stack.imgur.com/oiO6a.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oiO6a.png" alt="enter image description here"></a></p>
  
  <p>I attempted the below aswell but was not successful . </p>
  
  <pre><code>=IF(A2="B",MAX(SUM($B$2:B2)-OFFSET(A2,0,1),0),"")
  </code></pre>
  
  <p>i was thinking of opting into a vba code. </p>
  
  <p><strong>For Example:</strong></p>
  
  <p>With the <strong>first “B”</strong> is the sequence above, the <strong>remaining balance is zero (0)</strong> because 300 -100 leaving zero of the quantity left.  The <strong>remaining 200</strong> will be taken off 250 leaving a balance of <strong>50</strong>. </p>
  
  <p>The Remaining balance on B will always be zero</p>