+ Reply to Thread
Results 1 to 4 of 4

Simple IF Statement is not working (or I've lost my mind)

  1. #1
    Registered User
    Join Date
    07-17-2013
    Location
    Milton Keynes, England
    MS-Off Ver
    Excel 2007
    Posts
    3

    Unhappy Simple IF Statement is not working (or I've lost my mind)

    Can somebody help me, please?? I think I'm going mad!!

    I have a ridiculously simple spreadsheet containing values and a running total.

    I have written a simple IF statement to check that each total is correct.

    This is showing an error on some rows when there is nothing wrong.

    There is absolutely nothing complicated about this spreadsheet but I cannot for the life of me see what is happening!!

    In order to investigate I have created data that demonstrates the problem (attached).

    For example:

    Result:

    Value Total
    40 32461.00 32768.02
    41 -32461.00 307.02 ERROR but the total is correct
    42 32461.01 32768.03
    43 -32461.01 307.02
    44 32461.02 32768.04
    45 -32461.02 307.02
    46 32461.03 32768.05

    Showing formula for the same rows

    40 32461 32768.02 =IF(C39+B40=C40,"","ERROR")
    41 -32461 307.02 =IF(C40+B41=C41,"","ERROR")
    42 32461.01 32768.03 =IF(C41+B42=C42,"","ERROR")
    43 -32461.01 307.02 =IF(C42+B43=C43,"","ERROR")
    44 32461.02 32768.04 =IF(C43+B44=C44,"","ERROR")
    45 -32461.02 307.02 =IF(C44+B45=C45,"","ERROR")
    46 32461.03 32768.05 =IF(C45+B46=C46,"","ERROR")

    The problem only appears where there is a negative number in the value column and repeats in a strange pattern every 50 rows until it gets to row 61441 where it shows an error on every row with a negative number in the value column.
    Attached Files Attached Files

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Simple IF Statement is not working (or I've lost my mind)

    The way that excel calculates sometimes results in very small discrepancies, e.g. C40+B41 is giving a result of 307.019999999997 which doesn't quite match 307.02. The normal solution is to round to a large number of decimal places, e.g. use this formula in row 3 copied down

    =IF(ROUND(C2+B3,9)=C3,"","ERROR")

    This article explains what's happening
    Last edited by daddylonglegs; 08-02-2013 at 05:30 PM.
    Audere est facere

  3. #3
    Registered User
    Join Date
    07-17-2013
    Location
    Milton Keynes, England
    MS-Off Ver
    Excel 2007
    Posts
    3

    Smile Re: Simple IF Statement is not working (or I've lost my mind)

    That worked a treat - thank you so much.

    I can cancel the appointment with the shrink now.

  4. #4
    Registered User
    Join Date
    07-17-2013
    Location
    Milton Keynes, England
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Simple IF Statement is not working (or I've lost my mind)

    ... the article made for very interesting reading.

    I was aware of the problems due to floating-point arithmetic but had not realised that this could affect a simple addition of negative numbers.

    Thanks again.

+ 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] Simple nested IF statement not working correctly
    By bassemsaad in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-04-2013, 08:53 AM
  2. Simple transfer of information??! So lost.
    By KThomas in forum Excel General
    Replies: 9
    Last Post: 12-18-2012, 05:40 PM
  3. Working While Statement Stops Working
    By Verbaruab in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-10-2011, 05:58 PM
  4. Working out interest lost on a loan
    By [email protected] in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-28-2006, 04:40 AM
  5. Replies: 7
    Last Post: 05-22-2006, 03:35 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