Here is what I have data wise - Note that I am fudging Column G formulas, that is not the issue. What I want to do is find the Max value of Column G for each range of stock prior to the qty being 0 in column F. So in other words in H2 I would want to see 3735. In h7 I want to see 50, in h9 = 5120 and then in h14 =1850. I would like the other cells in column H to remain blank. Then I can sort to find the max cost for each security during the time period we held it. Any thoughts?
I would consider using a helper column for this...or using VBA. In this example, I've added a helper column (col. I) that contains the logic used to indicate subgroups whose maxima are to be determined. The data table is assumed to be sorted such that each type of stock is grouped together, and then within each stock grouping, the transactions are in ascending data order. Then the subgroups shown in the helper column are defined by either a change in stock or when a 0 is encountered in column F. Those subgroups can be easily examined to confirm that they make sense. Then in column H, the FILTER function is used in conjunction with the helper column I subgroup to extract the Total Cost array for that subgroup and the MAX is taken. Regarding the point mentioned about assumptions, should the transaction in yellow be situated between the transactions in orange? A quick note about the helper column: in this case, it cannot be labeled in I1 as that will produce an error, so I1 should be left blank...the column can, however, be hidden.
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.