Round VBA function – How to round a number

Last Updated on January 11, 2023 by token

Round VBA Function – Description

The Round VBA function is used to round numbers with decimal places. How can we use the Round function? In place of the first argument of the function, enter the number you want to round. In place of the second argument, enter the number of decimal places to which you want to round the number. 

If you want to return a value with no decimal places, do not enter the second argument of the function. The result will be an integer. You can also obtain an integer after using the VBA Fix or VBA Int functions .

VBA Round function – Syntax

'OfficeInside.Org 
Round(Number, [NumDigitsAfterDecimal As Long]) 

Number : The number we want to round.

NumDigitsAfterDecimal : Optional argument. The number of decimal places to which you want to round the number.

Function return : Numeric value.

VBA Round function – Example

How to use Round function in VBA Excel? Below is an example of using the Round function in the VisualBasic Editor.

Example 1 : Rounding a number using Round function. The result will appear in the MsgBox window and the sheet cell.

'OfficeInside.Org
 Sub RoundFunctionExample() 
  MsgBox Round(5.123)
  MsgBox Round(987.123456, 2)
  Range("A1") = Round(3.141234, 3)
  MsgBox Round(Range("a1"), 2) 
 End Sub
Excel VBA functions - Round VBA function
Excel VBA functions – Round VBA function

VB Round function – Additional informations

  • If you do not enter the second argument of the function, VBA Round returns an integer value, without decimal places.

Round VisualBasic function – Where to use?

The function can be used in: Excel 2003, Excel 2007, Excel 2010, Excel 2013, Excel 2016 , Excel 2019.

The article is part of the VBA Excel function list. You can find a list of all VBA functions at this address: VBA functions.

Leave a comment

Your email address will not be published. Required fields are marked *

%d bloggers like this: