Hi everyone,
1.png

I'm looking for a macro to go through a date sorted table and work out a value for the profit.

For example, the macro searches from the last row, goes upwards till it hits "Pears". If the "Buy at" column for the first occurence of "Pears"
is filled, then add that number to the next occurence of a purchase of "Pears" and continue till an occurence of "Pears" has nothing in the "Buy at"
column but an entry in the "Sell at" column. When there is a value there, then the profit is entered in that row, in green (and a loss in red).
It is simply the sum of all buys taken subtracted from the sell price.

This continues upwards through the table. There may be 10 types of fruit listed.

Any advise on how to accomplish this would be appreciated.

Thanks in advance!

James