+ Reply to Thread
Results 1 to 17 of 17

formatting of a cell to 2 decimal places

  1. #1
    Registered User
    Join Date
    02-24-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    10

    formatting of a cell to 2 decimal places

    So here's the problem.
    if I change the formatting of a cell to 2 decimal places, it appears as two decimal places (as it should) for example $88.88888 will show as $88.88

    However, when I use this data in another application that displays this data it will display as 88.88888 still. I need to actually take the value and truncate it to 88.88 eg 8.8888888 will become 8.88

    I have been using trunc by hand and wanted to try and find out if there is a way that I could write some sort of macro to do this for me each time.

    Any help on the subject would be great as VBA is still new to me
    Last edited by JohnD0e; 03-02-2010 at 11:51 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: formatting of a cell to 2 decimal places

    for example $88.88888 will show as $88.88
    It would display as $88.89

    If the value is a resuly of a formula, then you can integrate runding into the formula:

    =ROUND(my formula except for the = sign, 2)
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: formatting of a cell to 2 decimal places

    Put this macro in a standard module.

    Select the cells to truncate and then run the macro...

    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: formatting of a cell to 2 decimal places

    Are you sure you want to truncate and not round?

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: formatting of a cell to 2 decimal places

    This version seems to work without looping:
    Please Login or Register  to view this content.
    If you want to round instead, that's a simple tweak:
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 02-24-2010 at 02:45 AM.

  6. #6
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,592

    Re: formatting of a cell to 2 decimal places

    How about this:

    =INT(B2*100)/100

    or this:

    =ROUNDDOWN(B1;2)

    Edit: But I obviously misunderstand issue :D
    Last edited by zbor; 02-24-2010 at 03:06 AM.

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: formatting of a cell to 2 decimal places

    Sorry, the codes above were tweaked...here are the two again...make a selection of cells, then run the macro of choice:
    Please Login or Register  to view this content.

  8. #8
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: formatting of a cell to 2 decimal places

    Your post does not comply with Rule 8 of our Forum RULES. Cross-posting is when you post the same question in other forums on the web. You'll find people are disinclined to respond to cross-posts because they may be wasting their time solving a problem that has been solved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser)to the cross-post. Expect cross-posts without a link to be closed a message will be posted by the moderator explaining why. We are here to help so help us help you!

    http://www.mrexcel.com/forum/showthread.php?t=450611

  9. #9
    Registered User
    Join Date
    02-24-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: formatting of a cell to 2 decimal places

    First I must apologize I read the rules but missed this important note of rule 8 "on the web" and ausemed it was talking about cross posting on this forum.

    Second I want to thank each and every one that has posted I have not gone through all of the idea yet as I just rolled out of bed and saw the broken rule so though it was best to post here first.

    I am blown away by the amount of help that was given I have never been on a forum where so many people have made such helpful posts.

    To answer shg question as this values are money values I don't think I should be changing the amount if the value is 88.88888 I think i should show it as 88.88 and not try and do any rounding. I know there is a saying if you look after the pennies the pounds will look after them selves but it this case I will ignore that saying.


    And to confirm with rule 8 here is a copy of the post on Mr Excels Forum

    I will start by testing out all ideas once I get in to work tonight

  10. #10
    Registered User
    Join Date
    02-24-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: formatting of a cell to 2 decimal places

    Well at my second job for the day so now at last have time to have a play with the examples

    I would love to go with the Truncate method if I ran things but I think the Round (up) method is what a company would want to with having though about it today :-(


    JBeaucaire went with your code as it was pretty much ready to run. One thing I know users tend to do is that rather than select a range they will select the whole column.

    I have tried to fix this by adding the following code block by doing a "if not" statement it works but is this the correct way to not run this code on blank cells ?

    Please Login or Register  to view this content.
    The only other issue I can see is that first record is a header record what is the correct method to skip the first record. I was thinking to do a check to see if the cell had a number value in it but I don't think that's best way as some times the header might be a number.
    Last edited by JohnD0e; 02-24-2010 at 10:05 PM.

  11. #11
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: formatting of a cell to 2 decimal places

    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    02-24-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: formatting of a cell to 2 decimal places

    Crap have to take a step back made a error in the check for empty cells it was not working correctly.

    I am trying this

    Please Login or Register  to view this content.
    and I am pretty sure there needs to be a little bit more code

  13. #13
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: formatting of a cell to 2 decimal places

    Here you go, this will work even if they select the entire column:
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    02-24-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: formatting of a cell to 2 decimal places

    JBeaucaire,
    I tested this last night and you wrapped up every thing thank you for showing me how to set a range as well as and correctly use the IsNumeric funcion :-) will try and break it again when I get in to work tonight.
    but at the moment it seems pretty full proof so thank you for taking the time to help me.

  15. #15
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: formatting of a cell to 2 decimal places

    If that takes care of your need, use the Thread Tools menu to mark the this thread as [SOLVED].

    (Also, use the blue "scales" icon in our posts to leave Reputation Feedback, it is appreciated. It is found across from the "time" in each of our posts.)

  16. #16
    Registered User
    Join Date
    02-24-2010
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: formatting of a cell to 2 decimal places

    Strange I can't see how to put this as solved PS I added Rep points

  17. #17
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: formatting of a cell to 2 decimal places

    Click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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