Round several values to multiples of 100 and round the sum of all the values to 50000

manojrf

Board Regular
Joined
Mar 28, 2011
Messages
107
cash chest test new 10.1.16.xls
ABCDEFGHIJKLM
1CurrencyPiecesValueResultBalance
210010471047001047000710001500104710470
35083141550415005015083030002924830104700
420124248024008048012075007430120146200
510140140014000001401401500015000140148600
6Total150130150000130150000
Sheet1
Cell Formulas
RangeFormula
C2:C5C2=A2*B2
D2:D5D2=A2*L2
E2:E5E2=C2-D2
F2:F5F2=RIGHT(B2,1)
J2J2=M6/100
K2:K5K2=M3/A2
L2L2=MIN(K2,IF(B2="",0,B2))
J3J3=M6/50
L3L3=MIN(K3,B3,I3)
J4J4=M6/20
L4:L5L4=IF($G$5+(RIGHT($G$4,2)*1)=(RIGHT($G$3,3)*1),B4,MIN((M5/A4),I4,H4))
G3:G5G3=A3*F3
I2I2=FLOOR(B2,100)
I3,I5I3=FLOOR(B3,2)
H4H4=FLOOR(B4,5)
H5H5=FLOOR(B5,10)
J5J5=M6/10
C6:E6C6=SUM(C2:C5)
M2:M5M2=M3-D2
M6M6=FLOOR(C6,50000)



Hello everyone,

I hope everybody is keeping fine.

As shown in the table above, the value in column "Pieces" changes always. Whatever the total value or pieces be, what I have tried to do is round the value in column "Value". But the value in "D6" should be rounded to 50000 always.
I have tried my best to use my brain and formulas to do this. Is there anyone who could find an easier way to do this, either a formula or a macro?
Please try. Thanks in advance
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
In D6, does this give the result you want:
=FLOOR(SUMPRODUCT($A$2:$A$5,$B$2:$B$5),50000)
This preserves the other values in the col C & D and relies only on the original values in cols A & B.
 
Upvote 0
Thanks KRice for spending your precious time for me.

cash chest test new 12.06.2020.xls
ABCDEFGHIJKLMNOPQ
1CurrencyPiecesValuePiecesResultPiecesBalance
21001255125500100210020025325300512001500100210020
3509254625092446200150525092430002928924100200
4201242480120240048048012075007440120146400
510127127012012007707701201261500015000120148800
6Total17550015000025500150000
Sheet1
Cell Formulas
RangeFormula
J2:J5J2=RIGHT(B2,1)
N2N2=Q6/100
O2:O5O2=Q3/A2
P2P2=MIN(O2,IF(B2="",0,B2))
N3N3=Q6/50
P3P3=MIN(O3,B3,M3)
N4N4=Q6/20
P4:P5P4=IF($K$5+(RIGHT($K$4,2)*1)=(RIGHT($K$3,3)*1),B4,MIN((Q5/A4),M4,L4))
K3:K5K3=A3*J3
M2M2=FLOOR(B2,100)
M3,M5M3=FLOOR(B3,2)
L4L4=FLOOR(B4,5)
E2:E5E2=F2/A2
H2:H5H2=I2/A2
L5L5=FLOOR(B5,10)
N5N5=Q6/10
C2:C5C2=A2*B2
C6,I6,F6C6=SUM(C2:C5)
F2:F5F2=A2*P2
I2:I5I2=C2-F2
Q2:Q5Q2=Q3-F2
Q6Q6=FLOOR(C6,50000)


My question would have been a bit confusing.
What I am trying to do is to take out the right number of pieces from column "B", keeping their values rounded to 100, put it in column "E" and all in all keeping the total sum rounded to 50000, in F6.
Here in the given table, 7 is taken out from B5, 4 from B4, 1 from B3 and 253 from B2. From column J to Q, I have some formulas to make this work automatically.
I was wondering whether there is an easy way to do this.

Thanks again.
 
Upvote 0
Try something like this:
Book1
ABCDEFGHI
1CurrencyPiecesValuePiecesResultPiecesBalance
21001255125500100210020025325300
3509254625092446200150
42012424801202400480
51012712701201200770
6Total17550015000025500
Sheet2 (2)
Cell Formulas
RangeFormula
E2:E5E2=B2-H2
H2:H5H2=I2/A2
C2:C5C2=A2*B2
C6,I6C6=SUM(C2:C5)
F2F2=E2*A2
F3:F5F3=FLOOR(C3,100)
F6F6=FLOOR(SUMPRODUCT($A$2:$A$5,$B$2:$B$5),50000)
I2I2=C6-F6-SUM(I3:I5)
I3:I5I3=C3-F3

This rounds down to the nearest 100 in column F (except for the 100's currency) and then uses that value to establish the allocation of the total value for that row between columns E-F and H-I. SUMPRODUCT is used in F6 with FLOOR to round down the grand total to the nearest 50000. Then any residual is accounted for when making the allocation for the 100's currency.
 
Upvote 0
Once again thanks a lot. Your plan works out fine.
But what if I add three more currencies as shown in the table.

cash chest test new 12.06.2020.xls
ABCDEFGHI
1CurrencyPiecesValuePiecesResultPiecesBalance
22000122244000113226000918000
35004515225750045002257500157500
420055891117800550011000008917800
5100124112410012361241005500
6509274635092646300150
72012625201252500120
81016216201601600220
9Total3793890375000043890
Sheet2
Cell Formulas
RangeFormula
I3:I4I3=A3*H3
E2:E8E2=B2-H2
H6:H8H6=I6/A6
C2:C8C2=A2*B2
C9,I9C9=SUM(C2:C8)
F2,F4F2=E2*A2
F3F3=FLOOR(C3,500)
F5:F8F5=FLOOR(C5,100)
F9F9=FLOOR(SUMPRODUCT($A$2:$A$8,$B$2:$B$8),50000)
I6:I8I6=C6-F6


Please share your idea.

Sorry to bother you again

Thanks.
 
Last edited:
Upvote 0
I don't think there is a unique way to do this, but if we apply the same rule set that I described earlier, then it can be extended to the higher value currencies as shown here. With this approach, since you want (I think) all totals of every currency rounded down to the nearest 100, we apply that rule everywhere, even for the larger currencies. Note that all higher level currencies that end in "00" do not actually need to be rounded since they are already some multiple of 100 (but this approach retains the rounding formula for them anyway to preserve the same approach on all rows except for the 100's currency). The only exception to the rounding rule is for the 100's currency, since the rounding errors that accumulate will have to be offset there. The two formulas that make up this offset are shaded in orange on the 100's row. And the same rule set that determines the allocation of pieces for all other currencies remains the same. This means that in the Balance for the 100's currency, the sum of the balances of all removed pieces for larger and smaller currencies is taken, and then subtracted from the difference between the un-rounded grand total value (in C9) and the rounded grand total value (downward to the nearest 50000) in F9. It is somewhat arbitrary how this correction can be made. You could, for example, choose to make up the total balance (the amount shown in I9) by applying a different rule set for rounding the higher level currencies to some other value. Please let me know if this is what you had in mind, or if you wanted to apply a different set of rules for higher currencies.
20200613_Book1.xlsx
ABCDEFGHI
1CurrencyPiecesValuePiecesResultPiecesBalance
2200012224400012224400000
3500451522575004515225750000
4200558911178005589111780000
510012411241008038030043843800
6509274635092646300150
72012625201252500120
81016216201601600220
9Total3793890375000043890
10check -->3750000
Sheet6
Cell Formulas
RangeFormula
E2:E8E2=B2-H2
H2:H8H2=I2/A2
C2:C8C2=A2*B2
C9,I9C9=SUM(C2:C8)
I6:I8,I2:I4I2=C2-F2
I5I5=C9-F9-SUM(I2:I4,I6:I8)
F6:F8,F2:F4F2=FLOOR(C2,100)
F5F5=E5*A5
F9F9=FLOOR(SUMPRODUCT($A$2:$A$8,$B$2:$B$8),50000)
F10F10=SUM(F2:F8)
 
Upvote 0
Once again, thanks a lot.

This works out fine. What I am trying to do is this.

Instead of removing 100's for the entire balance amount (in this case 43800), I am trying to distribute this amount to 200's,500's and 2000's, only if needed. In this case, we can remove 40 of 100, 289 of 200 and 4 of 500 to make this amount (43800). Because, if we rely the whole amount on 100's, in some cases the value in E5 may become below zero, with a minus sign. In the above table, if we put 302 in B5, E5 becomes -197.

When number of pieces in column B changes, the distribution will change.

I assume that you understand what I mean to do.

Thanks once again.
 
Upvote 0
Yes, I see your point. Do you have some rule set in mind that would give the preferred solution? In most cases, as I mentioned earlier, there is not a unique solution. Let's take your example...
In this case, we can remove 40 of 100, 289 of 200 and 4 of 500 to make this amount (43800).
I assume you meant 189 rather than 289 of the 200's currency. But there are many other approaches too....we could also remove 38 of 100, 190 of 200 and 4 of 500 to make up the same difference of 43800 due to rounding. The point is that there are dozens of other possibilities. Obviously one constraint is that we cannot remove more than is available, but what else would guide your thinking?

Here is a revised version that illustrates an issue introduced by the higher value currencies and all of the other constraints or objectives: 1) round down so that each currency retains a total value of some multiple of 100, 2) the total value of all retained currencies should be rounded down to the nearest 50000, and 3) most of the difference should be made up with the 100's currency. This approach comes close to satisfying these objectives, but it doesn't rigorously satisfy all of them. For example, here the algorithm leaves 400 more than desired in the retained section and falls 400 short in the removed section. Even here, one could remove one more unit of 500 (since it is available) and then put 1 unit of 100 back, or instead remove 8 more units of 50, or remove 20 more units of 20, and many more combinations. A second step would be needed to address this small imbalance, but additional rules would be needed to describe the priorities. On the other hand, this may be close enough for your purposes?
20200613_Book1.xlsx
ABCDEFGHI
1CurrencyPiecesValuePiecesResultPiecesBalance
220002244000224400000
350015750012600031500
420033660000336600
5100200200000020020000
6509274635092646300150
72012625201252500120
81016216201601600220
9Total12859010040028190
10target -->100000target -->28590
Sheet6
Cell Formulas
RangeFormula
E2:E8E2=B2-H2
H2:H5H2=MIN(INT(($I$10-SUMPRODUCT(H3:H$8,A3:A$8)) /A2),B2)
H6:H8H6=(C6-FLOOR(C6,100))/A6
C2:C8C2=A2*B2
C9,I9,F9C9=SUM(C2:C8)
F2:F8F2=E2*A2
F10F10=FLOOR(SUMPRODUCT($A$2:$A$8,$B$2:$B$8),50000)
I2:I8I2=H2*A2
I10I10=C9-F10
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,541
Members
449,089
Latest member
davidcom

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