Solved

Using the Round function in VBA code in Excel

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…

696 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