I need to calculate the loan balance necessary in months to account for any shortfall in cash. The loan balance is calculated as the loan balance from the previous month minus the ending cash balance at the end of the current month. If the ending cash balance is positive, you will pay down as much of the loan balance from the previous month as possible. If the cash balance is negative, the loan balance will increase. I need to set up my formula so that if the cash balance at the end of a given month exceeds the loan balance from the previous month, the loan balance for the current month will be zero.

Example numbers below:

Cash Flows (Net): -$12,400.00 -$10,700.00 $700.00

Ending Cash Balance -$7,400.00 -$10,700.00 $700.00

Loan** $7,400.00 $10,700.00 $10,000.00