Help with a formula

levy77

Board Regular
Joined
May 7, 2019
Messages
67
[TABLE="class: cms_table, width: 576"]
<tbody>[TR]
[TD]Hi guys,[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 9"]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.[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 9"]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.[/TD]
[/TR]
[TR]
[TD="colspan: 9"]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).[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 9"]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.[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 8"]Keep in mind that another partial lot of shares could be sold but in this example this doesn't occur.[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 4"]If you need further explanation please let me know.[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 2"]Thanks for your help![/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


[TABLE="class: grid, width: 576"]
<tbody>[TR]
[TD="width: 64"]Company[/TD]
[TD="width: 64"]Date[/TD]
[TD="width: 64"]Units Purchased[/TD]
[TD="width: 64"]Purchase Price[/TD]
[TD="width: 64"]Total Cost[/TD]
[TD="width: 64"]Units Sold[/TD]
[TD="width: 64"]Unit price[/TD]
[TD="width: 64"]Total Return[/TD]
[TD="width: 64"]Capital Gain[/TD]
[/TR]
[TR]
[TD="width: 64"]ANZ[/TD]
[TD="width: 64, align: right"]20/05/2016[/TD]
[TD="width: 64, align: right"]100[/TD]
[TD="width: 64, align: right"]10[/TD]
[TD="width: 64, align: right"]1,000[/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[/TR]
[TR]
[TD="width: 64"]BBOZ[/TD]
[TD="width: 64, align: right"]25/05/2016[/TD]
[TD="width: 64, align: right"]90[/TD]
[TD="width: 64, align: right"]9[/TD]
[TD="width: 64, align: right"]810[/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[/TR]
[TR]
[TD="width: 64"]BBOZ[/TD]
[TD="width: 64, align: right"]3/06/2016[/TD]
[TD="width: 64, align: right"]80[/TD]
[TD="width: 64, align: right"]8[/TD]
[TD="width: 64, align: right"]640[/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[/TR]
[TR]
[TD="width: 64"]BBUS[/TD]
[TD="width: 64, align: right"]5/06/2016[/TD]
[TD="width: 64, align: right"]70[/TD]
[TD="width: 64, align: right"]7[/TD]
[TD="width: 64, align: right"]490[/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[/TR]
[TR]
[TD="width: 64"]ANZ[/TD]
[TD="width: 64, align: right"]7/07/2016[/TD]
[TD="width: 64, align: right"]60[/TD]
[TD="width: 64, align: right"]2[/TD]
[TD="width: 64, align: right"]120[/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[/TR]
[TR]
[TD="width: 64"]BBOZ[/TD]
[TD="width: 64, align: right"]1/08/2016[/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64, align: right"]80[/TD]
[TD="width: 64, align: right"]11[/TD]
[TD="width: 64, align: right"]880[/TD]
[TD="width: 64, align: right"]160[/TD]
[/TR]
[TR]
[TD="width: 64"]ANZ[/TD]
[TD="width: 64, align: right"]5/08/2016[/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64, align: right"]140[/TD]
[TD="width: 64, align: right"]12[/TD]
[TD="width: 64, align: right"]1,680[/TD]
[TD="width: 64, align: right"]600[/TD]
[/TR]
[TR]
[TD="width: 64"]ANZ[/TD]
[TD="width: 64, align: right"]10/08/2016[/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64, align: right"]20[/TD]
[TD="width: 64, align: right"]13[/TD]
[TD="width: 64, align: right"]260[/TD]
[TD="width: 64, align: right"]220[/TD]
[/TR]
[TR]
[TD="width: 64"]BBOZ[/TD]
[TD="width: 64, align: right"]15/08/2016[/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64"][/TD]
[TD="width: 64, align: right"]90[/TD]
[TD="width: 64, align: right"]5[/TD]
[TD="width: 64, align: right"]450[/TD]
[TD="width: 64, align: right"]-280[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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