Code for looping

My purpose is that, each of username will have unique amount per month. And it need to be returned based on the Total from the latest date to the back.

If this month is May, then the first date to check is April, then March → Feb → Jan …

If that month (latest month) can cover the amount (Total >= amount), then the expected result is equal amount.

If it can not cover, then write the amount that month can partly cover. For example, case America, if that month have 200 (Total), then we write 200 in the expected result and then check the rest amount (1,500,000-200,000=1,300,000) in the rest months.

We will stop checking if Sum of Expected result equal unique amount of that username, the rest month after stop will return value “0” or blank.

Assume we will have 10 months or 100 months (many years need to be checked).

I prefer using looping or coding is faster and shorter.

Date format: YYYY-MM-DD

I hope you guys can support me on that.

Once again, I appreciate every contributions of you guys.

data.xlsx