Combine data in columns (A-Current portfolio, B-buys, C-sells, Result-resulting portfolio)

mackti

New Member
Joined
Sep 3, 2019
Messages
2
Hi all,

  1. I have a series of current investments in columns (fields = InvestmentName, Units, Value).
  2. I then have a series of newly acquired investments in columns (fields = InvestmentName, Units, Value). These may be additions to the current investments or new investments.
  3. I then have a series of sold investments in columns (fields = InvestmentName, Units, Value).they have to be in the current investments (you can’t sell what you don’t have nor can you sell more than you have).
My question is this – is there an easy way of doing this in Excel VBA?
I can (I actually have) written code) that loops through every investment in A, checks if any existing investment in B needs to be added to it and then checks if anything from C needs to be subtracted from A (via lookup). It then adds this to the output.
Then the code goes through any new investment in B (that isn’t in A) and adds it to the output as a new investment.
It somehow works but it seems convoluted. Is there an easier way to combine these three data sets? (A + B – C) that show the output? (with anything from A that is 100% sold isn’t shown in the results).
I’ve attached an example of the problem and below it the manual solution (well I created an example XLS & was going to attach it but system says I don't have that permission so I can't).
Any help ideas would be much appreciated.
If the way I’m doing it is the best way, then so be it. I’m also keen to learn smarter ways of doing these things (can also cut code looping time I imagine).
Cheers
Tim
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
hi, Tim

Maybe use a pivot table. It can combine data from multiple tables and not show data that nets to zero quantity.
Or very similar using a query table. Neither needs code but you could have a single code line for refreshing.

regards, Fazza
 
Upvote 0
hi, Tim

Maybe use a pivot table. It can combine data from multiple tables and not show data that nets to zero quantity.
Or very similar using a query table. Neither needs code but you could have a single code line for refreshing.

regards, Fazza

Thanks for the suggestion Fazza. After 25+ yrs of successfully avoiding understanding exactly what a pivot table was in Excel, maybe I need to turn my mind to it. I've always just turned to MS Access, vlookups,hlookups,indirect, nested ifs, filters, VBA code etc as solutions ;) Cheers, Tim
 
Upvote 0
Being unfamiliar with pivot tables, MS Access might be a good tool.

Though VBA within Excel might be even better - cause you don't need two different softwares. It probably is simple enough in VBA that it would be better to do that than learn pivot tables. It is not a simple pivot table (though not too bad if you're famiilar with SQL).
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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