Formula or VBA to "round" numbers for sales prices + issues with number/text/...

_SGX_

New Member
Joined
Feb 3, 2022
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Dear Forum,

It's been a while since I had to use the Excel wizards of this forum, but I can't wrap my head around an easy to use formula or VBA to "round" sales prices of a starting company that is obligated by (belgian) law to change the prices to specific decimals/roundings, because 1ct, 2ct,... isn't allowed to have people pay like that anymore, minimum is a 5ct.

Here's the list:
,00 ,01 ,02 --> ,00
,03 ,04 --> increase to ,05
,06 ,07 --> decrease to ,05
,08 ,09 --> increase to ,10

Examples:
3,99 = 4,00
3,32 = 3,30
3 = 3,00 = OK
3,2 = 3,20 = OK

My solution (not yet finished even) has multiple steps, multiple formulas, multiple IFs, trying to extract the last digit to see what needs to be done but I cannot get the decimals to always stay right, I had trouble getting my lookups to use digits instead of numbers as text,... Hopefully I'm missing some awesome formula to get me going in the right direction.

Some of the steps:
1. Make prices TEXT, so other manipulations can be done more easily
2. Editing the numbers that are already without 1 or 2 decimals (pretty much manually or with "if(len(A1)=3;A1&"0"): 3 --> 3,00 3,2 --> 3,20
--> But I think it would work better to try and find the comma, and then work from the number to the right of it (decimal digits)
3. Extracting last "number" using Value() of Right(A1;1)
4. IF formula to check if it's ending in 0,1,2,3 --> Becomes 0
5. IF Formula to check if it's ending in 4,5,6,7--> Becomes 5
6. IF Formula to check if it's ending in 8,9 --> Becomes 10
7. Adding the new ending digits to the starting numbers, seems to function except for no decimal numbers in start... somehow my formula makes 30 out of starting 3.
--> Using multiple IF statements to calculate what needs to be done. Example (but it's in Dutch Excel- =ALS(G3=9;D3+0,01;ALS(G3=8;D3+0,02;ALS(G3=0;D3;LINKS(D3;LENGTE(D3)-1))&G3))

Example Mini-sheet (this is new to me, seems awesome for assistance!)
Prijswijziging_Berdy_01.01.22.xlsx
ABCDEFGH
1Purchase PriceExtra column for calculating pricesSales PriceExtract last number,00-,02 --> ,00,03-,07 --> ,05,08-,09 --> ,10 + Adding up the numbers to original
2
37,1011,4511,9555511,95
46,3510,2410,7444510,75
519,5231,5032000320
68,4613,6514,1555514,15
730,0748,5149,0110049,010
810,7717,3817,8888817,90
96,6410,7111,2110011,210
100,000,000,50000,50
118,7814,1714,6777514,65
1224,4139,3739,8777539,85
1396,98156,45156,95555156,95
146,5110,5011000110
1522,1335,7036,2000036,200
16107,06172,73173,23335173,25
177,3211,8112,3110012,310
1827,8944,9945,4999945,50
195,398,709,200009,200
2012,3319,8920,3999920,40
217,2911,7612,2666512,25
2226,0041,9542,4555542,45
237,1611,5412,0444512,05
2424,4739,4839,9888840,00
257,1611,5412,0444512,05
2624,4739,4839,9888840,00
278,2413,2913,7999913,80
2831,8651,4051,9000051,900
297,1611,5612,0666512,05
3028,3145,6846,1888846,20
317,6112,2812,7888812,80
329,9216,0116,5110016,510
3331,7351,2051,7000051,700
347,9112,7513,2555513,25
3526,0041,9542,4555542,45
367,9712,8613,3666513,35
3725,0640,4340,9333540,95
383,946,356,855556,85
394,907,908,400008,400
408,0713,0213,5220013,520
413,876,246,744456,75
427,1311,5012000120
434,857,828,322008,320
4421,8035,1735,6777535,65
454,437,147,644457,65
466,8110,9911,4999911,50
473,916,306,800006,800
485,969,6110,1110010,110
4917,9028,8729,3777529,35
504,407,107,600007,600
514,497,257,755557,75
5212,3719,9520,4555520,45
539,7315,6916,1999916,20
5411,6918,8519,3555519,35
5529,9448,3048,8000048,800
56209,57338,10338,60000338,600
5715,2024,0024,5000024,500
Blad1
Cell Formulas
RangeFormula
D3:D57D3=IF(LEN(C3)<=3,VALUE("0"),VALUE(RIGHT(C3,1)))
E3:E57E3=IF(OR(D3=0,D3=1,D3=2),VALUE("0"),D3)
F3:F57F3=IF(OR(E3=3,E3=4,E3=5,E3=6,E3=7),VALUE("5"),E3)
G3:G57G3=IF(F3=9,C3+0.01,IF(F3=8,C3+0.02,IF(F3=0,C3,LEFT(C3,LEN(C3)-1))&F3))
A3:A56A3=I3*0.75
 
=IF(OR(VALUE(RIGHT(ROUND((C3-(TRUNC(C3,1))),2),1))=0,VALUE(RIGHT(ROUND((C3-(TRUNC(C3,1))),2),1))=5),C3,IF(AND(VALUE(RIGHT(ROUND((C3-(TRUNC(C3,1))),2),1))>0,VALUE(RIGHT(ROUND((C3-(TRUNC(C3,1))),2),1))<3),C3--TRUNC(C3,1),IF(AND(VALUE(RIGHT(ROUND((C3-(TRUNC(C3,1))),2),1))>=3,VALUE(RIGHT(ROUND((C3-(TRUNC(C3,1))),2),1))<=7),C3+(0.05-(C3-TRUNC(C3,1))),ROUND(C3,1))))

the issue is the blue bit above change it to

C3-(c3-trunc(c3,1))
Superb! This is EXACTLY what I needed. Any good resource that helped you become such an excel wizard? Thanks again Gordsky!!!
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Superb! This is EXACTLY what I needed. Any good resource that helped you become such an excel wizard? Thanks again Gordsky!!!
your welcome, I am by no means a wizz and most on here will have far better skills than me. Formulas are about thinking logically which is something I am not bad at. VBA code syntax is where i struggle
 
Upvote 0
Aren't you just rounding to the nearest 0.05 or did I miss something?

=MROUND(C3,0.05)

would seem to work for the examples you quoted in your initial post?
 
Upvote 0
Aren't you just rounding to the nearest 0.05 or did I miss something?

=MROUND(C3,0.05)

would seem to work for the examples you quoted in your initial post?
wouldn't mround fail if c3 were a negative number?? (doesnt the multiplier then have to be negative too?)
 
Upvote 0
I hadn't expected negative sales prices, to be honest, but you could cater for that with:

Excel Formula:
=MROUND(C3,0.05*SIGN(C3))
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,774
Members
452,353
Latest member
strainu

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