G1 Enter below formula
G2 Enter below formula and drag down as far as requiredCode:=IF(Sheet1!$D$2>SUM(Sheet2!$D$4:D4),D4,Sheet1!$D$2-SUM(Sheet2!$D$4:D4))
Formula tested on your sampl sheet. If there is problem with your original sheet change the reference and ranges accordingly.Code:=IF(Sheet1!$D$2>SUM(Sheet2!$D$4:D5),D5,Sheet1!$D$2-SUM(Sheet2!$D$4:D4))
regrads
Very nice sharing
Bookmarks