Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi,
I wanted to use the Roundup/RoundDown function in VBA. I wanted to avoid using "Application.Roundup" because this is very slow. Is there a function that does this? - or does anyone know how to write this? Thanks for your help. |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
VBA has a native Round function- it appears to use 4 and 5 as its
rounding decision points. Do you need to do something dramatically different? If yes, and you don't want to use Application.Whatever, you may need to use a Mid function to determine an amount to add to your starting number in order to perform your custom work. Dave O Eschew obfuscation |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
On Jun 3, 7:00*am, Jeff wrote:
I wanted to use the Roundup/RoundDown function in VBA. I wanted to avoid using "Application.Roundup" because this is very slow. Is there a function that does this? - or does anyone know how to write this? How flexible do you need it? If you are simply trying to round up and down to an integral value, use the Fix() function to round down, and use Fix(x+0.5) to round up. Note: Ordinarily, I would expect to use Int(); but it does probably does not do what you want with negative numbers (sigh). If you want to round up or down to a predetermined number of decimal places, the following might suffice: Fix(d*x)/d and Fix(d*x+0.5)/d, where "d" is 10^(number of decimal places). Caveat: This might not have the same result as the Excel RoundUp/Down functions due to anomalies with floating point arithmetic. If that's an issue for you, you will probably have to use Format and string functions. At that point, I suspect that Application.RoundUp/Down is faster; it is certainly easier. |
#4
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Thanks that is very helpful.
In most cases it is just 2 decimal places. I will look into fix and see what can be done. "joeu2004" wrote: On Jun 3, 7:00 am, Jeff wrote: I wanted to use the Roundup/RoundDown function in VBA. I wanted to avoid using "Application.Roundup" because this is very slow. Is there a function that does this? - or does anyone know how to write this? How flexible do you need it? If you are simply trying to round up and down to an integral value, use the Fix() function to round down, and use Fix(x+0.5) to round up. Note: Ordinarily, I would expect to use Int(); but it does probably does not do what you want with negative numbers (sigh). If you want to round up or down to a predetermined number of decimal places, the following might suffice: Fix(d*x)/d and Fix(d*x+0.5)/d, where "d" is 10^(number of decimal places). Caveat: This might not have the same result as the Excel RoundUp/Down functions due to anomalies with floating point arithmetic. If that's an issue for you, you will probably have to use Format and string functions. At that point, I suspect that Application.RoundUp/Down is faster; it is certainly easier. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
ROUNDUP and -1 | Excel Worksheet Functions | |||
=ROUNDUP(INT(0.xxx)) | Excel Worksheet Functions | |||
RoundUp help! | New Users to Excel | |||
how to use roundup | Excel Discussion (Misc queries) | |||
ROUNDUP | Excel Discussion (Misc queries) |