Subtract Amount From Cell Until It Reaches 0 multiple reminding amount
<p>My formula below subtracts a cell until it reaches zero, and moves to the next one.  The subtraction is based on the value “B”. Each time the formula comes across the value “B”, this action is performed.</p>

<p><strong>Question:</strong> I have been trying to advance this to formulae, in that each time “B” is found that cell is minuses until zero and those amount multiple by the adjacent price. 
could you please provide me with a formula which does this ?</p>

<p><strong>Example:</strong> when it comes across the first B the full value of 100 x 10 will be multiplied and the reminder 50 will be multiplied by 15 i.e. 50 x 15 price of the next A. These values will be summed.</p>

<p><a href="https://i.stack.imgur.com/lFm2q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lFm2q.png" alt="enter image description here"></a></p>

<blockquote>
  <p>=MAX(SUMIF($A$2:A2,"A",$B$2:B2)-SUMIF($A$2:$A$10,"B",$B$2:$B$10),0)</p>
</blockquote>

<p>The reminder of the 50 is coming from the difference between the B 150 - A 100 , which leaves 50 to be still absorbed . </p>

<p>Further Calculation for explanation:</p>

<p><a href="https://i.stack.imgur.com/Q3zJx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Q3zJx.png" alt="enter image description here"></a></p>

<p><a href="https://i.stack.imgur.com/XAq6t.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XAq6t.png" alt="enter image description here"></a></p>

<p>Apologies thats meant to say calculation of <strong>6000</strong></p>