#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 921
Default Roundup in VBA

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 427
Default Roundup in VBA

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,059
Default Roundup in VBA

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 921
Default Roundup in VBA

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ROUNDUP and -1 Epinn Excel Worksheet Functions 6 October 2nd 06 06:38 PM
=ROUNDUP(INT(0.xxx)) Dave F Excel Worksheet Functions 7 September 29th 06 08:28 PM
RoundUp help! fodman New Users to Excel 5 February 26th 06 03:25 PM
how to use roundup r4319hb Excel Discussion (Misc queries) 2 December 24th 05 01:27 PM
ROUNDUP frustratedwthis Excel Discussion (Misc queries) 2 July 28th 05 09:03 PM


All times are GMT +1. The time now is 05:41 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"