I was just modifying some old code and I noticed that some of the macros I had used "Round" and others I had used "Application.Round". Both forms seem to work OK. Is there some subtle difference between the two?
I was just modifying some old code and I noticed that some of the macros I had used "Round" and others I had used "Application.Round". Both forms seem to work OK. Is there some subtle difference between the two?
They use different rounding algorithms, which you should undedrstand if using them. See
http://support.microsoft.com/default.aspx?kbid=194983
PRB: Round Function different in VBA 6 and Excel Spreadsheet
Thus, if you see:
[VBA]Debug.Print Round(x, 2)[/VBA]
that is the VB/VBA function Round, which uses banker's rounding. If you see:
[VBA]Debug.Print Application.Round(x, 2)
Debug.Print Application.WorksheetFunction.Round(x, 2)[/VBA]
you are using the Excel ROUND function, which always rounds up if the digit you're checking is >= 5.
Patrick
FYI, Round is not supported in Excel 97, although the worksheetfunction version is if called upon in VBA.
Ken Puls, CMA - Microsoft MVP (Excel)
I hate it when my computer does what I tell it to, and not what I want it to.
Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar
This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!
Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!
xld, that is a GREAT reference on rounding. And it referred to an even better one. Arrrgh! Now I know why I used the spreadsheet Round. The Banker's round is an interesting technique, which I personally would never have a use for. However, in my youth as an engineer, I can look back and recall instances in which the Banker's round would have been more appropriate than the arithmetic round. Thanks to all of you for the informative response!
The Banker's Round.
On deposits they round down, on borrowing they round up. Or have I got it wrong?
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'