+ Reply to Thread
Results 1 to 14 of 14

Conditional formatting: round to the first non-zero decimal place

  1. #1
    Registered User
    Join Date
    08-21-2015
    Location
    Brussels, Belgium
    MS-Off Ver
    2013
    Posts
    33

    Conditional formatting: round to the first non-zero decimal place

    Hi again. I have decided to start a new threat as a follow-up to one I started earlier today: http://www.excelforum.com/excel-gene...-new-post.html

    I have two conditional rules that I have applied formatting to:
    1. If number >= 0.1, then display only 1 decimal place.
    Ex: 59862.56354 --> 59,862.6

    2. If number is <0 (ie negative numbers), display only 1 decimal place.
    Ex: -59862.56354 --> -59,862.6


    I need to add a third rule for numbers between 0 and 0.1 that says: "round up to the first non-zero decimal." I have a few numbers that look like .00017888959 and some that look like .049432423. I want them to display as .0002 and 0.05. Any ideas on how to do this?

    Thanks for all of your ideas!
    Last edited by Kabouterke; 12-16-2015 at 12:37 PM.

  2. #2
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Conditional formatting: round to the first non-zero decimal place

    Hello Kabouterke,

    ..numbers that look like .00017888959 and some that look like .049432423. I want them to display as .0002 and 0.05
    I don't think what you want would be possible within your specified criteria.

    Regards.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  3. #3
    Registered User
    Join Date
    08-21-2015
    Location
    Brussels, Belgium
    MS-Off Ver
    2013
    Posts
    33

    Re: Conditional formatting: round to the first non-zero decimal place

    Well, that's frustrating. I guess the only other option would be to use conditional formatting to display the text "<0.1" when this occurs.

  4. #4
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Conditional formatting: round to the first non-zero decimal place

    Hi Kabouterke,

    That would depend on your exact requirement.

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Conditional formatting: round to the first non-zero decimal place

    Another option is to use VBA to custom format each number as it is entered/changed. Let me know if you want to go that direction. I would need to have your file to be able to help with that.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Conditional formatting: round to the first non-zero decimal place

    Quote Originally Posted by Kabouterke View Post
    Well, that's frustrating. I guess the only other option would be to use conditional formatting to display the text "<0.1" when this occurs.
    [You can't do that with conditional formatting. <=wrong]

    My mistake, you can indeed.
    Last edited by 6StringJazzer; 12-17-2015 at 10:15 AM.

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Conditional formatting: round to the first non-zero decimal place

    This code will perform your specified formatting on any cell that changes and has a numeric value <0.1. That might not be exactly what you want depending on your data layout but it gives you the idea of what can be done.

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    08-21-2015
    Location
    Brussels, Belgium
    MS-Off Ver
    2013
    Posts
    33

    Re: Conditional formatting: round to the first non-zero decimal place

    Hi 6StringJazzer, thanks for your amazing help so far!!!


    So, I've been working on this on my end as well, and still haven't come to any definite solutions. In the process of working with this, however, I realized I'll have to add another rule. Here are the four rules so far:
    1. -456123.084356 --> -456,123.1
    2. -0.084356 --> -0.01
    3. 0.084356 --> 0.01
    4. 456123.084356 --> 456,123.1

    It's rule number 2 that I didn't realize I would need up to now. I'm just starting out with VBA, but will take your code and see if there's anyway that I can change this myself.

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Conditional formatting: round to the first non-zero decimal place

    Here is an update to deal with negative numbers
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    08-21-2015
    Location
    Brussels, Belgium
    MS-Off Ver
    2013
    Posts
    33

    Re: Conditional formatting: round to the first non-zero decimal place

    Thanks for the quick reply, 6StringJazzer. I've put this code into each individual tab's VBA window, and it's working brilliantly with most numbers! :D However, the numbers aren't automatically updating when the data source is updated. Only after clicking on each individual cell and refreshing it will it then round up to the closest decimal.

    Also, some cells aren't updating and after clicking the individual cells and refreshing, the links in these cells to the other workbook just disappear.

    Any idea what's going on?
    Last edited by Kabouterke; 12-17-2015 at 12:47 PM.

  11. #11
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Conditional formatting: round to the first non-zero decimal place

    It sounds like the numbers you want to format are resulting from formulas. Worksheet_Change does not recognize when the result of a formula changes, only if a value changes or if the actual formula changes. There are a couple of ways to deal with this but I would need to see your file. Can you attach it?

    Also, some cells aren't updating and after clicking the individual cells and refreshing, the links in these cells to the other workbook just disappear.
    And I don't understand at all what you mean by this. What "just disappears"?

  12. #12
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Conditional formatting: round to the first non-zero decimal place

    Quote Originally Posted by Kabouterke View Post
    I've put this code into each individual tab's VBA window....
    That will work but you have to make multiple copies of the same code that way. I didn't know you wanted to use it in multiple worksheets. If you attach your file I can show you how to restructure to put the code in one place and call it from worksheet module.

  13. #13
    Registered User
    Join Date
    08-21-2015
    Location
    Brussels, Belgium
    MS-Off Ver
    2013
    Posts
    33

    Re: Conditional formatting: round to the first non-zero decimal place

    Hi 6StringJazzer... thanks again for the help on all of this. I've sent you a PM with a link to where you can download the workbook.
    Last edited by Kabouterke; 12-18-2015 at 04:52 AM.

  14. #14
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Conditional formatting: round to the first non-zero decimal place

    I got the files. I thought it would be obvious from looking at the data, but it's not: Which data needs to be rounded? You have a LOT of data in there.

    Also, all of the data in the target file is links to the other file. That means that Excel can't readily determine when the values are changing. There are a couple of options:

    1. Put a button the file to run the macro to update formatting on all desired data
    2. Use the Macro dialog box to run the macro when desired

+ 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. [SOLVED] Sum of range picking up ^-10 decimal place. Is there a way to sum 2 decimal place only?
    By graym463 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-22-2015, 08:48 AM
  2. [SOLVED] How to round to nearest .01 and round down if thousands place is .005
    By dredre609 in forum Excel General
    Replies: 5
    Last Post: 09-29-2014, 11:47 AM
  3. [SOLVED] Is there a way to round this condition to 1 decimal place?
    By brians34 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-19-2013, 10:44 AM
  4. Numbers round down when a 5 is in the third decimal place using a formula
    By Jbagger in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-27-2007, 11:59 AM
  5. Replies: 3
    Last Post: 03-18-2006, 02:25 PM
  6. [SOLVED] Column Formatting-appears as a 2 decimal place
    By G4 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-09-2005, 05:05 AM
  7. [SOLVED] Custom formatting to force a decimal place
    By Mike K in forum Excel General
    Replies: 3
    Last Post: 07-31-2005, 06:05 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