Excel VBA RoundUp Function
If you have searched in VBA for the RoundUp function, you must not have found it because it is a Worksheet function. Therefore, to access the RoundUp function, we need to use the VBA Worksheet FunctionVBA Worksheet FunctionThe worksheet function in VBA is used when we need to refer to a specific worksheet. When we create a module, the code runs in the currently active sheet of the workbook, but we can use the worksheet function to run the code in a particular worksheet.read more class.
You are free to use this image on you website, templates, etc., Please provide us with an attribution linkHow to Provide Attribution?Article Link to be HyperlinkedFor eg:Source: VBA RoundUp Function (wallstreetmojo.com)
Before this, recollect the syntax of the RoundUp function.
Examples
Let us perform the task of rounding up the number “288.5264”. We will see all the numbers with this example.
Example #1 – When the Second Argument is Zero
Look at the below VBA codeVBA CodeVBA code refers to a set of instructions written by the user in the Visual Basic Applications programming language on a Visual Basic Editor (VBE) to perform a specific task.read more.
Code:
Sub RoundUp_Example1()
Dim k As Double
k = WorksheetFunction.RoundUp(288.5264, 0)
MsgBox k
End Sub
- When you run the above code, it will convert the provided number, i.e., 288.5264, to the nearest whole number, i.e., 289.
Example #2 – When the Second Argument is 1
Look at the below code to see what happens when we pass one as a second argument.
Sub RoundUp_Example2()
Dim k As Double
k = WorksheetFunction.RoundUp(288.5264, 1)
MsgBox k
End Sub
- This code will convert the given number to one decimal point, i.e., 288.6.
Example #3 – When the Second Argument is 2
Look at the below code to see what happens when we pass two as a second argument.
Sub RoundUp_Example3()
Dim k As Double
k = WorksheetFunction.RoundUp(288.5264, 2)
MsgBox k
End Sub
- This code will convert the given number to two decimal points, i.e., 288.53.
Example #4 – When the Second Argument is 3
Look at the below code to see what happens when we pass three as a second argument.
Sub RoundUp_Example4()
Dim k As Double
k = WorksheetFunction.RoundUp(288.5264, 3)
MsgBox k
End Sub
- This code will convert the given number to three decimal points, i.e., 288.527.
Example #5 – When the Second Argument is -1
Look at the below code to see what happens when we pass minus one as a second argument.
Sub RoundUp_Example5()
Dim k As Double
k = WorksheetFunction.RoundUp(288.5264, -1)
MsgBox k
End Sub
- This code will convert the given number to the nearest ten, i.e., 290.
Example #6 – When the Second Argument is -2
Look at the below code to see what happens when we pass minus two as a second argument.
Sub RoundUp_Example6()
Dim k As Double
k = WorksheetFunction.RoundUp(288.5264, -2)
MsgBox k
End Sub
- This code will convert the number to the nearest hundred, i.e., 300.
Example #7 – When the Second Argument is -3
Look at the below code to see what happens when we pass minus three as a second argument.
Sub RoundUp_Example7()
Dim k As Double
k = WorksheetFunction.RoundUp(288.5264, -3)
MsgBox k
End Sub
- This code will convert the number to the nearest thousand, i.e., 1000.
Like this, we can use the ROUNDUP function in VBA as part of the worksheet function class to round up the numbers based on the provided second argument.
Recommended Articles
This article has been a guide to VBA RoundUp. Here, we discuss how to use the VBA RoundUp Worksheet function for rounding up the given number based on the given argument with a downloadable Excel template. You can learn more about VBA from the following articles: –
- VBA WaitTimeValue Function in VBACount Numerical Values in VBAVBA Integer