+ Reply to Thread
Results 1 to 10 of 10

Nested IF Statement

Hybrid View

  1. #1
    Registered User
    Join Date
    05-14-2013
    Location
    Little Rock, Arkansas
    MS-Off Ver
    Excel 2010
    Posts
    3

    Nested IF Statement

    I have a spreadsheet that has Date of Report (column H), Date of Assignment (column J), and Close Date (column I).

    I need a function that will do the following and place value in column M.

    IF I=0 and J=0 then M= Today-H
    IF I=0 and J>0 then M= Today-J
    IF I>0 and J>0 then M= I-J
    IF I>0 and J=0 then M= I-H

  2. #2
    Valued Forum Contributor
    Join Date
    10-10-2012
    Location
    New York
    MS-Off Ver
    Excel 2007/2010
    Posts
    337

    Re: Nested IF Statement

    Try this in cell M1

    Formula: copy to clipboard
    =IF(AND(I1=0,J1=0),TODAY()-H1,IF(AND(I1=0,J1>0),TODAY()-J1,IF(AND(I1>0,J1>0),I1-J1,IF(AND(I1>0,J1=0),I1-H1,0))))
    Don't just use the answers provided for you. Try to understand how it works by reverse engineering or asking about it.

    Please mark the thread as [SOLVED] (Thread Tools->Mark thread as Solved) when answered.
    If you're happy with an answer given, please click the * under the person's name to boost their reputation.

  3. #3
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Nested IF Statement

    =IF(and(I2=0,J2=0),now()-H2,if(and(I2=0,J2>0),now()-J2,if(and(I2>0,J2>0),I2-J2,if(and(I2>0,J2=0),I2-H2))))

  4. #4
    Registered User
    Join Date
    05-14-2013
    Location
    Little Rock, Arkansas
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Nested IF Statement

    That worked. Thanks! I had the right idea but was making it waaay too difficult.

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,167

    Re: Nested IF Statement

    Formula: copy to clipboard

    =IF(AND(I=0, J=0), Today()-H,
    IF(AND(I=0, J>0), Today()-J,
    IF(AND(I>0, J=0), I-H,
    IF(AND(I>0, J=0), I-J,""))))



    Or, more specifically (and working):

    Formula: copy to clipboard

    =IF(AND(I2=0, J2=0), TODAY()-H2,
    IF(AND(I2=0, J2>0), TODAY()-J2,
    IF(AND(I2>0, J2=0), I2-H2,
    IF(AND(I2>0, J2=0), I2-J2,""))))




    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  6. #6
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,608

    Re: Nested IF Statement

    @daffodil

    As now() returns date and actual time, it might slow down calculations due to it's volatility,and produce false results ( don't know if it's the case here)

    Fi now()-J2 is larger than today()-J2. Personally I would suggest TODAY() (as OP only seems to need dates)

  7. #7
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Nested IF Statement

    I never even heard of Today()! This is great!

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,167

    Re: Nested IF Statement

    @Pepe: TODAY() is volatile too

    @daffodil11: if you compare TODAY() and NOW() you will not get a match. Equally, if the OP compares his dates to NOW() he's not going to match them either.


    Regards, TMS

  9. #9
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,608

    Re: Nested IF Statement

    Quote Originally Posted by TMShucks View Post
    @Pepe: TODAY() is volatile too
    Did I imply somewhere that it wasn't ? If so,as I already said, please excuse my poor command of the English language
    Last edited by Pepe Le Mokko; 07-23-2013 at 02:26 PM.

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,167

    Re: Nested IF Statement

    Did I imply somewhere that it wasn't ?
    Maybe not. Perhaps just my interpretation of the sentence:

    As now() returns date and actual time, it might slow down calculations due to it's volatility
    And then:

    Personally I would suggest TODAY()

    Hence, volatility is not a factor as both would cause a re-calculation.

+ 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] Nested If Statement - ISBLANK and ISNA in same statement?
    By Janc in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 04-23-2013, 09:00 AM
  2. I think it's a nested If statement....
    By SOS in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-04-2011, 11:36 AM
  3. Nested IF Statement Help...
    By The Boosh! in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-04-2011, 10:42 AM
  4. Nested IF statement
    By scantor145 in forum Excel General
    Replies: 7
    Last Post: 06-30-2011, 10:56 AM
  5. Replies: 6
    Last Post: 01-14-2009, 06:59 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