+ Reply to Thread
Results 1 to 6 of 6

Can't Compared Rounded numbers to 0 decimal places

  1. #1
    Forum Contributor
    Join Date
    06-06-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    181

    Can't Compared Rounded numbers to 0 decimal places

    Hi all,

    I am trying to write some VBA to compare a rounded number with a rounded number for example I have 1 number 0.5302 and another showing as 0.5308 but both show as 53% on my spread sheet therefore they equal the same and I want them to they equal the same. but when I write my code it recognises 0.5308 as higher than 0.5302. How can I adapt my code so it recognises the outputs as the same? I attach part of my code below:-

    Please Login or Register  to view this content.

    Any help greatly appreciated.

    Cheers,

    James

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,937

    Re: Can't Compared Rounded numbers to 0 decimal places

    You have to compare the values as 2 decimal values too, you say it yourself in the post, you know one is 0.5302 and the other 0.5308

    What you see is formatting not the actual number so you have to convert the numbers to decimals for the comparisson

    Please Login or Register  to view this content.
    I don't knwo if the syntax is right I just typed it in but this is the idea (red text)
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Forum Contributor
    Join Date
    06-06-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    181

    Re: Can't Compared Rounded numbers to 0 decimal places

    Hi Keebellah, I know that is what I need to do but I don't know how to write the VBA code for that part. I tried the above but couldn't get that to work. Tried with 0 instead if 2.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Can't Compared Rounded numbers to 0 decimal places

    James

    Why did you try 0?

    If you want to compare to 2 decimal places use 2 as Keeballah shows.
    If posting code please use code tags, see here.

  5. #5
    Forum Contributor
    Join Date
    06-06-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    181

    Re: Can't Compared Rounded numbers to 0 decimal places

    I don't want to compare to 2 decimal places I want to compare to 0. I have found the answer I have to use worksheetfunction.round. Thanks Keeballah.

  6. #6
    Forum Contributor
    Join Date
    06-06-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    181

    Re: Can't Compared Rounded numbers to 0 decimal places

    Hi there, Norie you are correct it does need to be to 2 decimal places the fact that I saw it as a percentage confused me.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Comparing numbers to two decimal places only
    By necht_angel in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-09-2017, 12:51 PM
  2. Need =IF statement to give me decimal places for numbers less than 1 not 0
    By gonefishing12345 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-05-2013, 11:59 AM
  3. [SOLVED] Round numbers to decimal places
    By bigband1 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 01-01-2013, 11:34 AM
  4. Replies: 4
    Last Post: 12-26-2012, 05:37 AM
  5. Replies: 3
    Last Post: 04-28-2011, 05:47 PM
  6. How? Count only numbers with 3 or more decimal places.
    By n2lectual in forum Excel General
    Replies: 1
    Last Post: 03-21-2008, 11:38 AM
  7. [SOLVED] My numbers format as a number with two decimal places.
    By Tim Poulter in forum Excel General
    Replies: 2
    Last Post: 09-17-2005, 09:05 PM
  8. Extract decimal places from numbers?
    By aijihz in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-09-2005, 05:09 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1