Round a number

To round a number we need to apply the Excel ROUND function

Example: Round a number

Round a number

METHOD 1. Round a number

EXCEL

=ROUND(B5,C5)
The formula uses the Excel ROUND function to round the selected number in cell B5 to the nearest integer.

METHOD 1. Round a number using VBA

VBA

Sub Round_a_number()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Analysis")
'apply the formula to round a number
ws.Range("D5") = Application.WorksheetFunction.Round(ws.Range("B5"), ws.Range("C5"))

End Sub

OBJECTS
Worksheets: The Worksheets object represents all of the worksheets in a workbook, excluding chart sheets.
Range: The Range object is a representation of a single cell or a range of cells in a worksheet.
PREREQUISITES
Worksheet Name: Have a worksheet named Analysis.
Value to Round: If using the exact VBA code ensure that the value that you want to round is captured in cell ("B5").
Number of Digits: The value (0) in cell ("C5") represents the number of digits that the selected number should be rounded. 0 represents a rounding to the nearest integer.

ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell reference ("D5") in the VBA code to any cell in the worksheet, that doesn't conflict with the formula.
Value to Round: Select the value that you want to round by changing the cell reference ("B5") in the VBA code to any cell in the worksheet that contains the value that you want to round and doesn't conflict with the formula.
Number of Digits: You can select the cell that contains the number of digits, which in this example will be 0, by changing the cell reference ("C5") to any cell in the worksheet, that contains a value of 0 and doesn't conflict with the formula. You can also hardcode the number of digits directly into the VBA code by replacing ws.Range("C5") with 0.

Explanation about the formula used to round a number

EXPLANATION

EXPLANATION
To round a number we need to apply the Excel ROUND function.
FORMULAS
=ROUND(number, num_digits)

ARGUMENTS
number: The number that is to be rounded.
num_digits: The number of digits that the specified number will be rounded to. In this example we have assigned a value of 0 to num_digits argument, meaning that the value will be rounded to the nearest integer.