WallStreetMojo

WallStreetMojo

WallStreetMojo

MENUMENU
  • Blog
  • Free Video Tutorials
  • Courses
  • All in One Bundle
  • Login
Home » Excel, VBA & Power BI » Learn VBA » VBA RoundUp Function

VBA RoundUp Function

By Jeevan A YJeevan A Y | Reviewed By Dheeraj VaidyaDheeraj Vaidya, CFA, FRM

Excel VBA RoundUp Function

Similar to worksheet function where we round up the  numbers to the closest integers, in VBA we have a RoundUp function which decrease the decimal point for us and the syntax to use the roundup function is as follows Round up ( Number, Number of Digits After Decimal) these two arguments in the function are mandatory.

When we work with numbers and calculations, we get fraction numbers after the whole number, and it is quite common in everyday business. We don’t generally bother about the decimal values because it doesn’t make any impact on our end result. In those situations, we need to round up the numbers to the nearest whole number or immediate whole number. By using the RoundUp function, we can actually perform this task.

If you have searched in VBA for the RoundUp function, then you must not have found it because it is a worksheet function. In order to access the RoundUp function, we need to use the VBA Worksheet Function class.

VBA-Roundup

Before this, recollect the syntax of the RoundUp function.

roundup function

Examples

You can download this VBA RoundUp Excel Template here – VBA RoundUp Excel Template

Let’s 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 code.

Code:

Sub RoundUp_Example1()

    Dim k As Double

    k = WorksheetFunction.RoundUp(288.5264, 0)

    MsgBox k

End Sub

vba roundup example 1.1

  • When you run the above code, it will convert the provided number, i.e., 288.5264, to the nearest whole number, i.e., 289

vba roundup example 1.2

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.

Popular Course in this category
Sale
VBA Training (3 Courses, 12+ Projects)
4.6 (247 ratings)
3 Courses | 12 Hands-on Projects | 43+ Hours | Full Lifetime Access | Certificate of Completion
View Course

Code:

Sub RoundUp_Example2()

    Dim k As Double

    k = WorksheetFunction.RoundUp(288.5264, 1)

    MsgBox k

End Sub

vba roundup example 2.1

  • This code will convert the given number to one decimal point, i.e., 288.6

vba roundup example 2.2

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.

Code:

Sub RoundUp_Example3()

    Dim k As Double

    k = WorksheetFunction.RoundUp(288.5264, 2)

    MsgBox k

End Sub

vba roundup example 3.1

  • This code will convert the given number to two decimal points, i.e., 288.53

vba roundup example 3.2

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.

Code:

Sub RoundUp_Example4()

    Dim k As Double

     k = WorksheetFunction.RoundUp(288.5264, 3)

     MsgBox k

End Sub

example 4.1

  • This code will convert the given number to three decimal points, i.e., 288.527

example 4.2

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.

Code:

Sub RoundUp_Example5()

    Dim k As Double

    k = WorksheetFunction.RoundUp(288.5264, -1)

    MsgBox k

End Sub

example 5.1

  • This code will convert the given number to the nearest ten, i.e., 290.

example 5.2

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.

Code:

Sub RoundUp_Example6()

    Dim k As Double

    k = WorksheetFunction.RoundUp(288.5264, -2)

    MsgBox k

End Sub

example 6.1

  • This code will convert the given number to the nearest hundred, i.e., 300.

example 6.2

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.

Code:

Sub RoundUp_Example7()

    Dim k As Double

    k = WorksheetFunction.RoundUp(288.5264, -3)

    MsgBox k

End Sub

example 7.1

  • This code will convert the number to the nearest thousand, i.e., 1000.

example 7.2

Like this, we can use the ROUNDUP function in VBA as part of the worksheet function class to rounding up the numbers based on the provided second argument.

Recommended Articles

This 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 Wait
  • TimeValue Function in VBA
  • Count Numerical Values in VBA
  • VBA Integer
5 Shares
Share
Tweet
Share
VBA Training (3 Courses, 12+ Projects)
  • 3 Courses
  • 12 Hands-on Projects
  • 43+ Hours
  • Full Lifetime Access
  • Certificate of Completion
LEARN MORE >>
Primary Sidebar
Footer
COMPANY
About
Reviews
Contact
Privacy
Terms of Service
RESOURCES
Blog
Free Courses
Free Tutorials
Investment Banking Tutorials
Financial Modeling Tutorials
Excel Tutorials
Accounting Tutorials
Financial Statement Analysis
COURSES
All Courses
Financial Analyst All in One Course
Investment Banking Course
Financial Modeling Course
Private Equity Course
Venture Capital Course
Excel All in One Course

Copyright © 2021. CFA Institute Does Not Endorse, Promote, Or Warrant The Accuracy Or Quality Of WallStreetMojo. CFA® And Chartered Financial Analyst® Are Registered Trademarks Owned By CFA Institute.
Return to top

WallStreetMojo

Free Excel Course

Excel functions, Formula, Charts, Formatting creating excel dashboard & others

* Please provide your correct email id. Login details for this Free course will be emailed to you

Book Your One Instructor : One Learner Free Class
Let’s Get Started
Please select the batch
Saturday - Sunday 9 am IST to 5 pm IST
Saturday - Sunday 9 am IST to 5 pm IST

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

WallStreetMojo

Free Excel Course

Excel functions, Formula, Charts, Formatting creating excel dashboard & others

* Please provide your correct email id. Login details for this Free course will be emailed to you

Login

Forgot Password?

WallStreetMojo

Download VBA RoundUp Excel Template

Special Offer - VBA Training Course (6 courses, 35+ hours video) View More