Sum to an exact max value using ranking

mtryon

New Member
Joined
Sep 7, 2022
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
I want to have the sum of E2:E11 equal to E13. Currently, my formula in cell E2 is =IF(SUMIF(D:D,"<="&D2,B:B)<=E$13,B2,"")
This is almost what I want, except that it only uses the whole amount in column B (which is why cell E12 is 131), when I'd want the remaining 9 to be taken from the next highest ranking number.

Lot A - Throwaway column to help identify everything
Quantity B - Total amount that can be used
Cost C - This is what rank 1 D is based off of
Rank 1 D - I want to use the highest ranking numbers first
Sale 1 E - E2:11 should equal Equal E13. E12 is the sum of E2:E11, which shows that the formula won't sell a partial amount.



Lot (A) Quantity (B)Cost (C)Rank 1 (D)Sale 1 (E)
1​
100​
10​
6​
2​
125​
25​
5​
3​
15​
35​
4​
4​
6​
8​
8​
5​
98​
7​
9​
6​
55​
99​
1​
55​
7​
75​
50​
3​
75​
8​
5​
3​
10​
9​
3​
10​
6​
10​
1​
70​
2​
1​
Total From above
131​
Target Amount
140​
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
How about:

Book1
ABCDE
1LotQuantityCostRankSale
211001060
321252550
43153549
546880
6598790
765599155
877550375
9853100
10931060
111017021
12Total from above140
13Target Amount140
Sheet8
Cell Formulas
RangeFormula
E2:E11E2=MEDIAN(0,B2,$E$13-SUMIF(D:D,"<"&D2,B:B))
E12E12=SUM(E2:E11)
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
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