Convert stock buys and sells into offsetting trades

BillJones984

New Member
Joined
Jul 3, 2018
Messages
1
Hi and thanks in advance for the help!

I need to convert stock buy and sell requests into matched offsetting trade transactions. The Buys and Sells here are the inputs and the trades are the outputs.

Answers in PQ are preferred but VBA or Excel are fine too.


[TABLE="width: 1363"]
<tbody>[TR]
[TD="colspan: 7, align: center"]Inputs[/TD]
[TD][/TD]
[TD="colspan: 8, align: center"]Outputs[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="colspan: 3, align: center"]Buy[/TD]
[TD][/TD]
[TD="colspan: 3, align: center"]Sell[/TD]
[TD][/TD]
[TD="colspan: 6, align: center"]Trades[/TD]
[TD][/TD]
[TD]Comments[/TD]
[/TR]
[TR]
[TD]Account[/TD]
[TD]Stock[/TD]
[TD]$ Price[/TD]
[TD][/TD]
[TD]Account[/TD]
[TD]Stock[/TD]
[TD]$ Price[/TD]
[TD][/TD]
[TD]Account[/TD]
[TD]Stock[/TD]
[TD]Buy $[/TD]
[TD][/TD]
[TD]Stock[/TD]
[TD]Sell $[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Jim[/TD]
[TD]BIDU[/TD]
[TD="align: right"]1500[/TD]
[TD][/TD]
[TD]Jim[/TD]
[TD]SBUX[/TD]
[TD="align: right"]1900[/TD]
[TD][/TD]
[TD]Jim[/TD]
[TD]TSLA[/TD]
[TD="align: right"]200[/TD]
[TD][/TD]
[TD]REGN[/TD]
[TD="align: right"]200[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Jim[/TD]
[TD]TSLA[/TD]
[TD="align: right"]200[/TD]
[TD][/TD]
[TD]Jim[/TD]
[TD]REGN[/TD]
[TD="align: right"]1100[/TD]
[TD][/TD]
[TD]Jim[/TD]
[TD]AMZN[/TD]
[TD="align: right"]300[/TD]
[TD][/TD]
[TD]REGN[/TD]
[TD="align: right"]300[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Jim[/TD]
[TD]AMZN[/TD]
[TD="align: right"]300[/TD]
[TD][/TD]
[TD]Jim[/TD]
[TD]TMUS[/TD]
[TD="align: right"]100[/TD]
[TD][/TD]
[TD]Jim[/TD]
[TD]MSFT[/TD]
[TD="align: right"]500[/TD]
[TD][/TD]
[TD]REGN[/TD]
[TD="align: right"]500[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Jim[/TD]
[TD]MSFT[/TD]
[TD="align: right"]500[/TD]
[TD][/TD]
[TD]Sally[/TD]
[TD]VOD[/TD]
[TD="align: right"]500[/TD]
[TD][/TD]
[TD]Jim[/TD]
[TD]ADBE[/TD]
[TD="align: right"]100[/TD]
[TD][/TD]
[TD]REGN[/TD]
[TD="align: right"]100[/TD]
[TD][/TD]
[TD]Need to sell $100 here so REGN is depleted[/TD]
[/TR]
[TR]
[TD]Jim[/TD]
[TD]ADBE[/TD]
[TD="align: right"]600[/TD]
[TD][/TD]
[TD]Sally[/TD]
[TD]SIRI[/TD]
[TD="align: right"]400[/TD]
[TD][/TD]
[TD]Jim[/TD]
[TD]ADBE[/TD]
[TD="align: right"]500[/TD]
[TD][/TD]
[TD]SBUX[/TD]
[TD="align: right"]500[/TD]
[TD][/TD]
[TD]Remaining ADBE is purchased with proceeds from SBUX[/TD]
[/TR]
[TR]
[TD]Sally[/TD]
[TD]FB[/TD]
[TD="align: right"]800[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Jim[/TD]
[TD]BIDU[/TD]
[TD="align: right"]1400[/TD]
[TD][/TD]
[TD]SBUX[/TD]
[TD="align: right"]1400[/TD]
[TD][/TD]
[TD]SBUX depleted[/TD]
[/TR]
[TR]
[TD]Sally[/TD]
[TD]AMZN[/TD]
[TD="align: right"]100[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Jim[/TD]
[TD]BIDU[/TD]
[TD="align: right"]100[/TD]
[TD][/TD]
[TD]TMUS[/TD]
[TD="align: right"]100[/TD]
[TD][/TD]
[TD]Remaining SBUX purchased with proceeds from TMUS[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Sally[/TD]
[TD]AMZN[/TD]
[TD="align: right"]100[/TD]
[TD][/TD]
[TD]SIRI[/TD]
[TD="align: right"]100[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Sally[/TD]
[TD]FB[/TD]
[TD="align: right"]300[/TD]
[TD][/TD]
[TD]SIRI[/TD]
[TD="align: right"]300[/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Sally[/TD]
[TD]FB[/TD]
[TD="align: right"]500[/TD]
[TD][/TD]
[TD]VOD[/TD]
[TD="align: right"]500[/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]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Total Buys[/TD]
[TD]Jim[/TD]
[TD="align: right"]3100[/TD]
[TD][/TD]
[TD]Total Sells[/TD]
[TD]Jim[/TD]
[TD="align: right"]3100[/TD]
[TD][/TD]
[TD="colspan: 2"]Net Trades[/TD]
[TD]Jim[/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Sally[/TD]
[TD="align: right"]900[/TD]
[TD][/TD]
[TD][/TD]
[TD]Sally[/TD]
[TD="align: right"]900[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Sally[/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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