There are certain amounts in Cells B1, C1, D1 AND G1. Now I want that the negative amount in C1 should be setoff with the positive amounts in B1 & D1. While setoff, the following things to be taken care of.

1) The negative amount in cell C1 should be setoff with the positive amount which has highest percentage and if the amount in D1 is not sufficient then the balance negative amount has to be setoff with the next percentage amount B1.

2) After that the negative amount in cell G1 should be set off with the positive amounts in cells B1 to D1 (subject to availability of positive amount).

3) Ignore, if cell G1 has a positive number or insufficient balance in cells B1 to D1 to cover negative amount in cell G1.