+ Reply to Thread
Results 1 to 8 of 8

Can I nest IF statements, if the first one is checking for data?

  1. #1
    Registered User
    Join Date
    02-07-2013
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Can I nest IF statements, if the first one is checking for data?

    Hi all,

    I'm trying to write a formula that will do the following:
    • Display the amount of days from a date to TODAY - (TODAY()-K2)
    • If another cell contains data, display the difference between the first and second date - (L2-K2)
    • Check to see if there is data in either data column, else leave blank - (=IF(K2="","",TODAY()-K2)

    I've tried the following:
    =IF(K2="","",TODAY()-K2,IF(L2="","",L2-K2))
    ...but it throws me a 'Too many arguments' error. I assume this is because I'm trying to check the cell for data first. Any ideas, or am I just asking too much on this one?

    Thanks a ton!

  2. #2
    Forum Expert judgeh59's Avatar
    Join Date
    02-07-2013
    Location
    Boise, Idaho
    MS-Off Ver
    Excel 2016
    Posts
    2,310

    Re: Can I nest IF statements, if the first one is checking for data?

    your second IF statement is the problem....take a look at the "&" and concatenate the two formulas together....HTH
    Ernest

    Please consider adding a * if I helped

    Nothing drives me crazy - I'm always close enough to walk....

  3. #3
    Valued Forum Contributor
    Join Date
    07-27-2012
    Location
    Dublin, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    826

    Re: Can I nest IF statements, if the first one is checking for data?

    Barnaclebot, welcome to the forum.

    Can you clarify your last condition, please? Is it if EITHER K2 OR L2 is blank, return blank?
    Brendan.


    __________________________________________________________________________________________________
    Things to consider:

    1) You can thank any poster by clicking the * at the left of a helpful post.
    2) You can help to keep the forum tidy by marking your thread as "Solved", if it has been answered to your satisfaction.
    3) Help us to help you, by uploading a sample workbook, showing the type of data you're dealing with, and clearly indicating what the results should be.

  4. #4
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Can I nest IF statements, if the first one is checking for data?

    The problem is in the logic that you are using.

    The first part of the formula "=IF(K2="","",TODAY()-K2" is a complete IF statement because both the TRUE and FALSE parts of the statement are taken care of. If K2 is blank, return a blank otherwise subtract K2 from Today's date.

    The second part of the formula "IF(L2="","",L2-K2)" is also a complete IF statement for the same reason as above but there is a complication that you added and that is IF(k2="".... If K2 is blank, the formula will not proceed to the IF(L2=""... because the TRUE statement for K2 is satisfied. If K2 is not blank then K2 is subtracted from today's date and the formula has done its job and will not proceed further.

    In effect, you have two conflicting IF statements rolled up in one equation.
    <---------If you like someone's answer, click the star to the left of one of their posts to give them a reputation point for that answer.
    Ron W

  5. #5
    Registered User
    Join Date
    02-07-2013
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Can I nest IF statements, if the first one is checking for data?

    Hi Brendan, thanks for the welcome! I've lurked here before for answers, everyone always seems super helpful.

    Correct, if either K2 or L2 is blank, return blank. Overall what I'd like to have happen is if K2 contains a date but L2 is blank, have the cell display the number of days difference from K2 to today. If L2 also contains a date, have the cell display the difference between K2 and L2.

    I could be totally wrong in my original formula. Thanks for any advice!

  6. #6
    Registered User
    Join Date
    03-02-2013
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    67

    Re: Can I nest IF statements, if the first one is checking for data?

    This formula should help you. Syntax for Nested If Condition.
    =IF(Condition,ValueToBeReturnedIfConditionResultsInTrue,ValueToBeReturnedIfConditionResultsIn)
    Result of Condition should be True or False. Parameter 2 and/or 3 can become another IF Condition totally. In the sample given below Parameter2 is made into another IF Condition.
    English Version of the below IF Condition is
    IF L2 is Blank then
    Return
    IF K2 is Blank then
    Return the information both dates are blank
    ELSE
    Return Today - K2
    ENDIF
    ELSE
    Return L2-K2
    ENDIF


    Please Login or Register  to view this content.
    Last edited by tgsekhar; 03-14-2013 at 08:15 PM. Reason: Indents corrected for easy understanding
    If I have helped, click on the * below the post

  7. #7
    Registered User
    Join Date
    02-07-2013
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Can I nest IF statements, if the first one is checking for data?

    tgsekhar, thank you! That makes much more sense than what I was trying to do.

    Thanks everyone!

  8. #8
    Forum Expert newdoverman's Avatar
    Join Date
    02-07-2013
    Location
    Port Dover, Ontario, Canada
    MS-Off Ver
    2010
    Posts
    10,330

    Re: Can I nest IF statements, if the first one is checking for data?

    I think that the possibility of K2 being blank while L2 isn't blank hasn't been considered and no outcome has been specified if only L2 has a date. This formula will allow you to specify the outcome if K2 is blank and L2 is not blank.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    The possibilities are:
    1) K2 and L2 are not blank....L2 - K2
    2) K2 and L2 are both blank...."Both Dates are Blank"
    3) K2 is not blank and L2 is blank....today()-K2
    4) K2 is blank and L2 is not blank....""

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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