Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel VBA Round Function: A How-To Guide

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

The VBA Round function rounds a number to a specified number of decimal places, and it uses banker's rounding (round half to even) rather than the round-half-up rule most people expect from Excel worksheets. To use it, call Round(expression, [numdecimalplaces]) in a macro or the Immediate window, for example Round(2.5, 0) returns 2, not 3. This guide shows how to apply it correctly, avoid the most common surprise, and fix results that look wrong.

What You'll Need

  • Excel on Windows or Mac with macros enabled (the Developer tab visible, or access to the Visual Basic Editor via Alt+F11 on Windows, or the Developer tab on Mac).
  • A workbook saved as .xlsm if you want to keep your macro.
  • Basic familiarity with opening the Visual Basic Editor and inserting a module.

Step-by-Step

  1. Open the Visual Basic Editor. Press Alt+F11 on Windows. On Mac, use the Developer tab and choose Visual Basic. Menu labels can differ slightly by Excel version and region.
  2. Insert a standard module. In the editor, choose Insert > Module. A blank code window appears. You can also test one-liners in the Immediate window (Ctrl+G on Windows) without a module.
  3. Write a basic Round call. Type a line such as MsgBox Round(3.14159, 2) and press F5 to run it. The message box shows 3.14. The first argument is the number or expression; the second is how many decimal places you want.
  4. Round to whole numbers. Use 0 as the second argument: Round(7.6, 0) returns 8, and Round(7.4, 0) returns 7. Omitting the second argument also rounds to a whole number.
  5. Round to the left of the decimal point. Use a negative second argument: Round(1234.56, -2) returns 1200, and Round(1234.56, -1) returns 1230. This is useful for reporting figures in hundreds or thousands.
  6. Round a variable, not just a literal. Declare a variable and pass it in: Dim x As Double: x = 2.675: MsgBox Round(x, 2). The result depends on the stored binary value, so test with your real data rather than assuming.
  7. Understand banker's rounding. When the digit after the rounding position is exactly 5 and nothing follows, VBA rounds to the nearest even number: Round(2.5, 0) gives 2, Round(3.5, 0) gives 4, Round(0.5, 0) gives 0. This is by design and differs from the worksheet ROUND function, which rounds half away from zero.
  8. Get round-half-up behaviour if you need it. Use WorksheetFunction.Round(number, digits) inside VBA to match Excel's worksheet rule, or add a small adjustment such as Round(x + 0.0000001, 2) only after testing that it does not distort your data. For financial reporting that must match a worksheet formula, WorksheetFunction.Round is usually the safer choice.
  9. Format the output for display. Round changes the value; it does not add trailing zeros. To show 3.10 rather than 3.1, apply a number format to the cell, for example Range("A1").NumberFormat = "0.00", or use Format(Round(x, 2), "0.00") when building a string.
  10. Write the result back to a cell. Assign it directly: Range("B2").Value = Round(Range("A2").Value, 2). This is the most common real-world use: cleaning imported or calculated values before they feed a report.
  11. Test edge cases before relying on it. Check negative numbers (Round(-2.5, 0) returns -2), values already at the target precision, zero, and very large or very small numbers. Save the workbook as .xlsm so the code persists.

Common Mistakes

  • Expecting worksheet ROUND behaviour. VBA Round uses banker's rounding, so 2.5 becomes 2. If your totals must match a worksheet formula, use WorksheetFunction.Round instead.
  • Confusing rounding with formatting. Round changes the stored value; cell formatting only changes what is displayed. A cell showing 3.10 may still hold 3.1 or 3.0999.
  • Assuming decimal arguments are exact. Many decimal fractions cannot be stored exactly in binary, so a number that looks like it ends in 5 may round unpredictably. Test with the actual values from your data.
  • Passing text instead of a number. If a cell contains text that looks numeric, Round can raise a type mismatch. Convert first with CDbl or Val after checking the data.
  • Using Round for currency without checking. For money, decide whether you need banker's rounding or half-up, and document the choice so reports reconcile.
  • Forgetting the second argument. Omitting it rounds to a whole number, which may silently drop decimals you wanted to keep.

Tips

  • Use the Immediate window to try expressions quickly: type ?Round(2.5,0) and press Enter.
  • Keep a small helper function in your module if you always need half-up rounding, so the rule is applied consistently across macros.
  • Round at the last possible moment. Rounding intermediate values and then summing can produce totals that differ from rounding the final result.
  • Use negative decimal arguments for rounding to tens, hundreds or thousands instead of dividing and multiplying.
  • Combine Round with Format when building text for emails or reports, so the displayed precision matches the stored precision.
  • Add a comment next to any Round call that depends on banker's rounding, so the next person editing the macro understands the result.

Troubleshooting

If the result is not what you expected, work through these checks in order.

  1. Check the value, not the display. Select the cell or use the Immediate window to print the underlying number. A formatted cell can hide unrounded decimals.
  2. Confirm which rounding rule you are using. VBA Round is banker's rounding; WorksheetFunction.Round is half-up. Switch functions if the rule is the problem.
  3. Check the data type. If the argument is text, convert it to a number before rounding. Use IsNumeric to test first.
  4. Look for floating-point artefacts. If a value that should round one way rounds the other, print it with many decimal places to see the stored value.
  5. Verify the decimal argument. A missing or zero second argument rounds to a whole number; a negative one rounds left of the decimal point.
  6. Step through the code. Use F8 in the Visual Basic Editor to run line by line and inspect variables in the Locals window.
  7. If the macro will not run at all, check that macros are enabled and the file is saved in a macro-enabled format. If the problem persists, restart Excel and test in a blank workbook before changing your main file.

Frequently Asked Questions

Why does VBA Round(2.5, 0) return 2 instead of 3?

VBA uses banker's rounding, which rounds exact halves to the nearest even number. That reduces bias in large sets of rounded figures. Use WorksheetFunction.Round if you need half-up behaviour.

Does VBA Round work the same as the ROUND worksheet function?

No. They differ on exact halves. Worksheet ROUND rounds half away from zero; VBA Round rounds half to even. For values that are not exact halves, the results usually match.

How do I round to the nearest thousand in VBA?

Use a negative decimal argument: Round(12345, -3) returns 12000. The same pattern works for tens and hundreds.

Can I round and keep trailing zeros?

Rounding changes the value, not its display. Apply a number format to the cell or use the Format function to show trailing zeros.

What happens if I leave out the second argument?

VBA rounds to a whole number. Round(3.7) returns 4.

Why does rounding a cell value sometimes give an unexpected result?

The stored value may not be exactly what is displayed, because decimal fractions are stored in binary. Print the value with more decimal places to see what Round is actually working with.