Vlookup with multiple values and a limiter

levy77

Board Regular
Joined
May 7, 2019
Messages
67
Hi guys,

I am trying to use a vlookup up to calculate whether a capital gain or loss has been made or lost when selling shares. A major problem I have is; if shares are purchased in two separate lots and at different prices, when I sell a portion of the shares I need to calculate the capital gain or loss on all the first lot of shares, if I sell more shares than I bought in the first lot then I need to move onto the second lot I bough. Then when I sell the rest of the shares at a later date I need to take off from the amount of shares I have left after selling the first lot.

For example, in the table below, 100 units of ANZ were purchased on 20/5/2016 and a further 60 units of ANZ were purchased on 7/7/2016.
140 units of ANZ were then sold on the 5/8/2016 so the capital gain is worked out by Total return-Total Cost=Capital Gain. However, the Total Cost in this case is 100 units at $10 + 40 units at $2 =$1,080. Therefore, the Capital Gain in this case is $1,680-$1,080=$600. When the further 20 ANZ shares are sold the cost will be the remaining amount of shares (40*$2).

BBOZ sale is similar to ANZ. However, the first sale cost comes from the first purchase and the cost of the second sale of BBOZ comes from 10 units in the first buy then the remaining from the second lot.

Keep in mind that another partial lot of shares could be sold but in this example this doesn't occur.

If you need further explanation please let me know.

Thanks for your help!

CompanyDate
Units PurchasedPurchase PriceTotal CostUnits SoldUnit priceTotal Return
Capital Gain
ANZ
20/5/2016100101,000
BBOZ25/5/2016909810
BBOZ3/6/2016808640
BBUS5/6/2016707490
ANZ7/7/2016602120
BBOZ1/8/20168011880160
ANZ5/8/2016140121,680600
ANZ10/8/20162013260220
BBOZ15/8/2016905450-280

<tbody>
</tbody>
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,213,527
Messages
6,114,148
Members
448,552
Latest member
WORKINGWITHNOLEADER

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top