+ Reply to Thread
Results 1 to 9 of 9

Formula sometimes works using [h]:mm; cell time format

  1. #1
    Registered User
    Join Date
    07-05-2019
    Location
    Perth, Australia
    MS-Off Ver
    Office 365 Business Premium
    Posts
    5

    Formula sometimes works using [h]:mm; cell time format

    Have a column to check if timesheet add-up correct. Am getting a ##### error sometimes and othertimes get what 0:00 result when using formula: =IF(G21="","",G21-SUM(I21:P21))
    G21 is the sum of start, end, & breaks times. Columns I-P are the division of total work hours (G21). The problematic QC formula is the check if G21 and the sum of projects are equal & equal 0:00 hours. Note: All cells are in custom cell format: [h]:mm;
    EXAMPLE:
    cell G21 formula: =IF(D20="","",($E20-$D20)-F20)
    cell G21 result: 8:30
    cells I21-P21 values: 0:30/1:00/1:30/0:30/1:00/1:30/2:00/0:30
    cell I21-P21 result: 8:30
    cell Q21 checking formula: =IF(G21="","",G21-SUM(I21:P21))
    Sometimes given Q21 result of 0:00 and other times #######

    Please advise
    Attached Files Attached Files
    Last edited by rkoch123; 07-11-2019 at 12:51 AM. Reason: uploaded example spreadsheet

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Formula sometimes works using [h]:mm; cell time format

    To best describe or illustrate your problem you would be better off attaching a dummy workbook. The workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    To attach a file to your post,
    click advanced (next to quick post),
    scroll down until you see "manage file",
    click that and select "add files" (top right corner).
    click "select files" find your file, click "open" click "upload" click 'done" bottom right. click "submit reply"

    Once the upload is completed the file name will appear below the input boxes in this window.
    You can then close the window to return to the new post screen.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

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

    Re: Formula sometimes works using [h]:mm; cell time format

    I expect that the problem is simple floating point error. ####### is technically not an error, but simply Excel's way of saying that it cannot display the cell's value using the assigned number format. Excel's time formats cannot display negative times -- even if the negative value is something like -1.1E-15 (which, if it could be displayed as 0:00:00 would display as -00:00:00).

    As a debugging step, I would change the number format of the cell to scientific 0.00E+0 and see what the actual value of the calculation is. I expect you will find a tiny negative number that, for all practical purposes, is 0.

    Solutions to floating point errors is usually to use one of Excel's rounding functions to force an exactly 0 result when the result suggests that it should be exactly 0.

    More information that you probably want to know about floating point error here: https://www.excelforum.com/groups/ma...nd-errors.html
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Registered User
    Join Date
    07-05-2019
    Location
    Perth, Australia
    MS-Off Ver
    Office 365 Business Premium
    Posts
    5

    Re: Formula sometimes works using [h]:mm; cell time format

    Thanks Ford. I've uploaded an example spreadsheet. Please note that the cells are custom format is [h]:mm; (with an 'at' symbol at the end)
    Struggling with the formula in column Q.

  5. #5
    Registered User
    Join Date
    07-05-2019
    Location
    Perth, Australia
    MS-Off Ver
    Office 365 Business Premium
    Posts
    5

    Re: Formula sometimes works using [h]:mm; cell time format

    Hi MrShorty,
    I believe you are correct. The value returned is -5.55111512312578E-17
    If this is the case, how would I force excel to round the time?

  6. #6
    Registered User
    Join Date
    07-05-2019
    Location
    Perth, Australia
    MS-Off Ver
    Office 365 Business Premium
    Posts
    5

    Re: Formula sometimes works using [h]:mm; cell time format

    I think I solved it by investigating the floating point error mentioned by Mr.Shorty!!

    For this, I put a ROUND() to two digits within the IF(). And it works!!!

    Corrected Formula:
    =IF(G21="","",ROUND(G21-SUM(I21:P21),2))

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,830

    Re: Formula sometimes works using [h]:mm; cell time format

    Yes, it will be the floating point error!

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

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

    Re: Formula sometimes works using [h]:mm; cell time format

    Glad you got something that works. The only thing I might add is that you are rounding to the nearest 0.01 (1 hundredth of a day or 14.4 minutes). This means that you are never expecting to reconcile times closer than about +/- 15 minutes. If the sums are within about 15 minutes of each other, you are forcing them to be seen as the same. If that is your intention, then great. If not, you may want to think more carefully about how closely you expect the times to reconcile and choose a "fraction of day" that better reflects your need to reconcile times.

  9. #9
    Registered User
    Join Date
    07-05-2019
    Location
    Perth, Australia
    MS-Off Ver
    Office 365 Business Premium
    Posts
    5

    Re: Formula sometimes works using [h]:mm; cell time format

    Quote Originally Posted by MrShorty View Post
    Glad you got something that works. The only thing I might add is that you are rounding to the nearest 0.01 (1 hundredth of a day or 14.4 minutes). This means that you are never expecting to reconcile times closer than about +/- 15 minutes. If the sums are within about 15 minutes of each other, you are forcing them to be seen as the same. If that is your intention, then great. If not, you may want to think more carefully about how closely you expect the times to reconcile and choose a "fraction of day" that better reflects your need to reconcile times.
    Good point. Yes, I noticed that was an issue when a 1/2 hour was represented as 00:28 when rounding to two decimal places. I've extended the decimal places to 5 decimal places resulting in 00:30 which reflects the true value.

+ 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. Replies: 4
    Last Post: 10-05-2017, 09:37 AM
  2. [SOLVED] time sheet help, format TIME and formula based on the actual time entered.
    By bh mng in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 12-06-2016, 01:10 PM
  3. Code works when cell is manually changed only the first time and not with vba
    By sdl2 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-17-2014, 08:18 PM
  4. [SOLVED] Macro/Formula/VBA to change time format and data in a cell?
    By Masken in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-11-2014, 10:21 AM
  5. Formula works but Run Time Error 13 Type Mismatch in VBA
    By uberathlete in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-29-2013, 10:05 PM
  6. Change format of lots of data cell to a time format
    By dazza67 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 03-24-2013, 03:24 PM
  7. Time insert that works with formula
    By Oly Steel Man in forum Excel General
    Replies: 2
    Last Post: 03-01-2011, 11:12 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