Book8.xlsx

I have a list of stock transactions (and options transactions for those familiar with them). What I need to do is create a table where I can see a Stock Symbol, the Date I bought shares, and the Date I sold the last of those shares bought.

In some scenarios I buy and sell the same stock multiple times, so I can't do simple lookup formulas. In other scenarios, I don't sell all shares on the same date, so I can't just lookup the "buy to close" date. I need to either find a way to lookup when the "buy to open" qty gets down to 0 and what date that occurs, or, lookup the last "buy to close" date before the next "buy to open" date (and if there is no next "buy to open" date, get the most recent "buy to close" date)

In my attached example, you'll see two stocks: DB and MLNX. The DB example has a buy date for 300 shares on 1/23 and a sell date for those shares on 2/17. The next buy date is 6/26 for 500 shares and sell date of 8/17. In theory, I need a table like the one i have to the right of that information on the spreadsheet (new lines for each buy/sell combo)

In the example for the second stock, I sell shares on two different dates, so I would need the latest sell date. However, if I go out and buy MLNX again, please be sure to account for that in the code as simply looking for MAX value won't work for what I need.

Keep in mind, my goal is to have one macro I can run that will list all stocks, along with their open and close date

Thanks a ton in advance. Post any questions you have for me here.