Solved

Using the Round function in VBA code in Excel

Posted on 2001-06-08
3
184 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 100 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

688 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