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
Solved

Using the Round function in VBA code in Excel

Posted on 2001-06-08
3
179 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
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

809 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