+ Reply to Thread
Results 1 to 7 of 7

Automate number of decimal places

  1. #1
    Forum Contributor
    Join Date
    06-27-2014
    Location
    bristol, england
    MS-Off Ver
    excel 2007
    Posts
    264

    Automate number of decimal places

    Hi All

    I have 2 sheets in a workbook (may add more), most cells for entering numbers are set to NO decimal places, another 4 cell on each row are set to convert figures and show the result to 4 decimal places, these have all been set and all works fine. but there will be occasions when the cells displaying to 4 decimal places, will need to be changed to 5 decimal places, can this be done via VBA, I don't really have to go through all the cells and change them manually if it can be done using vba


    many thanks for any help


    scouse13

  2. #2
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: Automate number of decimal places

    Deleted.
    Code changed the non formatted cells also.
    Last edited by jolivanes; 07-02-2018 at 12:32 PM.

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Automate number of decimal places

    Depending on exactly what determines the decision to be 4 or 5 decimal places, I doubt VBA is required for this. A lot depends on how you are deciding when to display 4 and 5 digits, which your OP does not explain.

    Custom number formatting can handle limited conditions -- for example, if "smaller" numbers should have 5 digits and "larger" numbers should have 4 digits, with a clear demarcation between "small" and "large". See this help file: https://support.office.com/en-us/art...2-09fab54be7f4

    More elaborate conditions can be handled using conditional formatting: https://support.office.com/en-us/art...c-65d913033d18 Usually the hardest part is developing the conditions or formula that tests the conditions as part of the conditional formatting.

    If your conditions for choosing which format to apply are extremely complex or difficult to formulate, then VBA may be preferred. IMO, it seems that your logic must be pretty convoluted not to fit into the "use a formula to decide what formatting to apply" part of conditional formatting.

    Which approach would you like to use?
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Forum Contributor
    Join Date
    06-27-2014
    Location
    bristol, england
    MS-Off Ver
    excel 2007
    Posts
    264

    Re: Automate number of decimal places

    hi mrshorty

    thanks for your reply, the people using the spreadsheet will decide whether 4 0r 5 decimal places should be used as it will depend on the level of accuracy for the converted cells, I was thinking of maybe an option button or checkbox when set to true could change the relevant cells from 4 to 5 places

    scouse13

  5. #5
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: Automate number of decimal places

    This will toggle between 4 and 5 decimals. Don't know how "fast" it is though.
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    06-27-2014
    Location
    bristol, england
    MS-Off Ver
    excel 2007
    Posts
    264

    Re: Automate number of decimal places

    thanks jolivanes, before I try it will this change all the cells to this format, as it is only certain cells I need changing

    scouse13

  7. #7
    Forum Expert
    Join Date
    10-06-2008
    Location
    Canada
    MS-Off Ver
    2007 / 2013
    Posts
    5,528

    Re: Automate number of decimal places

    If you want to change only certain cells, we need to know the sheet names or sheet index numbers and the cell addresses that need changing.

    BTW, you should always try macro suggestions on a copy of your original any way. Never on the original.

    Re: "depend on the level of accuracy for the converted cells"
    Accuracy for calculations is not affected by decimals showing.
    What you see in the cells is strictly visual.
    Last edited by jolivanes; 07-02-2018 at 06:25 PM. Reason: Add info

+ 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. Adusting decimal places based on greatest number of places in a series
    By anelson87 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-11-2022, 01:05 PM
  2. Replies: 12
    Last Post: 09-22-2017, 01:46 PM
  3. [SOLVED] Need to limit the number of decimal places of a number in a text string
    By Turbo Dog in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-11-2013, 07:47 PM
  4. [SOLVED] copy number with 3 or more decimal places and paste the actual value as 2 decimal number
    By k1dr0ck in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-29-2013, 12:57 AM
  5. Vba to format number of decimal places dependant on number in another cell
    By wonderdunder in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-10-2012, 09:33 AM
  6. number of decimal places
    By Geordie in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-22-2010, 03:06 AM
  7. Paste two decimal number in excel without extra decimal places appearing
    By jeffery_frick in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-13-2009, 07:49 PM

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