?
Solved

Using the Round function in VBA code in Excel

Posted on 2001-06-08
3
Medium Priority
?
188 Views
Last Modified: 2010-05-02
Hi all
I'm trying to round a number so that it has 2 decimal places. However I've come across this bizarre incident where by the following gives me 2 ??

x = Round(2.005, 2)

I expected it to return me 2.01

Any help would be hugely appreciated
Paul
0
Comment
Question by:skintpaul
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Accepted Solution

by:
chandukb earned 400 total points
ID: 6169091
This code works:

Dim x As Single
x = Application.WorksheetFunction.Round(2.005, 2)
MsgBox x

I just tried.

hope this helps.

Chandu

0
 
LVL 3

Expert Comment

by:jrspano
ID: 6169092
this is a 3rd same question delete it
0
 
LVL 1

Expert Comment

by:rmariman
ID: 6169101
Is the type of x able to contain decimals?
I just tried this out in Excel 97 VBA and I cannot find a builtin Round function!
Entering this in an excel cell it works correctly.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 16 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question