In the file I had attached in post #5, use

C5=MIN(B5-C$3,C$3) and drag down

D5=MIN($B5-SUM($C$3,$C5:C5),D$3) and drag down and across