+ Reply to Thread
Results 1 to 4 of 4

Cells look the same and equal but are not!

  1. #1
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Cells look the same and equal but are not!

    Why B4 is not equal to C4?
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-01-2014
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    1,795

    Re: Cells look the same and equal but are not!

    Quote Originally Posted by drgkt View Post
    Why B4 is not equal to C4?
    First, you should format them as Custom [h]:mm:ss, since you are computing a sum of time. Then you would see that the number of hours is 51, not 3.

    Second, for debugging purposes, if you temporarily format them as Number with 14 decimal places, you would see the difference: 2.13710648148149 in B4 v. 2.13710648148148 in C4. And that is only approximate; the actual difference (B4-C4) is about 8.88E-15.

    It is very common to encounter such infinitesimal differences. The problem arises because Excel time is stored as a fraction of a day, which is a non-integer. And most non-integers cannot be represented exactly in 64-bit binary floating-point, which Excel uses internally to represent numbers.

    To remedy this, change the formulas as follows:

    B4: =--TEXT(SUM(B6:B438),"[h]:mm:ss")
    C4: =--TEXT(SUM(C6:C438),"[h]:mm:ss")

    The TEXT function ensures that time is rounded to the same internal binary representation as the time constant that you might write. The double negate ("--") converts text to number.
    Last edited by joeu2004; 12-19-2015 at 12:08 AM.

  3. #3
    Forum Contributor
    Join Date
    01-20-2014
    Location
    Greece
    MS-Off Ver
    20 yr. old Excel 2002!
    Posts
    710

    Re: Cells look the same and equal but are not!

    W O W !
    Did not even occur to me to question the fact that the number of hours was too little! I would look like a fool reporting this sum! Thanks

    Now I changed B4 as per your formula and C1 turned to TRUE before I did the same to C4. Why is that?

    BUT MOST IMPORTANT...

    Elsewhere I utilize this formula =SUMPRODUCT($I$18:$I$452;--($A18:$A452="SomeCategory");--($H18:$H452=0)) which I suspect is wrong since column I contains cells representing time.
    How should I modify this one?

    Thanks again

  4. #4
    Forum Expert
    Join Date
    05-01-2014
    Location
    California, US
    MS-Off Ver
    Excel 2010
    Posts
    1,795

    Re: Cells look the same and equal but are not!

    Quote Originally Posted by drgkt View Post
    Elsewhere I utilize this formula =SUMPRODUCT($I$18:$I$452;--($A18:$A452="SomeCategory");--($H18:$H452=0)) which I suspect is wrong since column I contains cells representing time. How should I modify this one?
    Similar to before:

    =--TEXT(SUMPRODUCT($I$18:$I$452;--($A18:$A452="SomeCategory");--($H18:$H452=0));"[h]:mm:ss")

    formatted as Custom [h]:mm:ss.

    But you might not need to do that. It depends on how you use the result of the formula.

    If you compare or add it to or subtract it from other times, it is prudent to round it as demonstrated above.

    However, if you do nothing with the result other than display it, you might get away without rounding it.

    Quote Originally Posted by drgkt View Post
    Now I changed B4 as per your formula and C1 turned to TRUE before I did the same to C4. Why is that?
    Are you asking: why did you only need to change B4, not also C4, even though it is prudent to change both?

    The answer is: Excel is trying (too hard) to simplify things for you. In this case, it misleads you into thinking B4 and C4 are equal, when in fact they are not.

    The formula in C1 is essentially =(B4=C4), which returns TRUE. But if the formula were =(B4-C4=0), the result is FALSE(!).

    [EDIT] Another example: =MATCH(B4,C4,0) returns a #N/A error, indicating there is truly no match.

    Of course, the two formulas are the same algebraically; so the result should be the same.

    The second formula is the correct result, numerically. That is, if you change only B4, it truly is different from C4. Note that =SUM(B4,-C4) formatted as Scientific displays about -2.66E-15.

    The difference in the first formula is: sometimes, if two values are "close enough", Excel arbitrarily treats them as equal. The operative word is "sometimes". Excel is not consistent about when it applies that rule.

    So again, IMHO, it is prudent to round all time formulas used in comparisons (for example), rather than take a chance with Excel's inconsistently applied rule.
    Last edited by joeu2004; 12-19-2015 at 04:06 AM. Reason: cosmetic; MATCH example

+ 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: 3
    Last Post: 09-26-2014, 12:12 PM
  2. Multiple Cells values - formula to see which cells added together equal zero?
    By rodders0223 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-15-2013, 11:09 AM
  3. Replies: 2
    Last Post: 09-06-2013, 02:25 PM
  4. Replies: 2
    Last Post: 08-06-2013, 03:27 PM
  5. Compare two cells, if equal move a third cells data to another cell
    By eriick in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-24-2013, 05:38 PM
  6. [SOLVED] Counting cells in a column to add formulas to that equal number of cells
    By flipjarg in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-11-2012, 11:45 AM
  7. Creating a loop to make cells equal other cells
    By Tuneman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-17-2010, 07:40 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