+ Reply to Thread
Results 1 to 17 of 17

If and statement

  1. #1
    Registered User
    Join Date
    05-21-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    9

    If and statement

    If and statement help

    I have a SS with 2 columns (dates).
    in some instances column 1 may be blank, while column 2 has a value entered, visa versa or both columns may be blank.

    My goal is to find the number of days between the two dates in column 1 and 2

    *if column 1 contains text and column 2 does not, i'd like to find the difference between todays date and column 1 date

    *if neither column contains text id like column 3 to remain blank

    I have entered the following formula, but am getting responses of 40,000 days, can anyone help me figure out where i've gone wrong?

    =IF((AND(A2="*",B2="")),(TODAY()-A2),(B2-A2))
    Last edited by tykuhn99; 05-27-2011 at 01:27 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: If and statement

    Small correction:

    =IF((AND(A2<>"",B2="")),(TODAY()-A2),(B2-A2))



    My version of the same logic:

    =IF(A2="", "", MIN(B2, TODAY()) - A2)
    Last edited by JBeaucaire; 05-21-2011 at 10:41 AM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: If and statement

    What happens when Column B has a date and Column A is blank?
    Please Login or Register  to view this content.
    [EDIT]
    J.B.s' second formula is probably the correct one, just thought I'd check.
    Last edited by Marcol; 05-21-2011 at 10:54 AM.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  4. #4
    Registered User
    Join Date
    05-21-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: If and statement

    thanks for the help guys, unfortunately the SS is on my computer that I left at work. can't wait to try it out on monday (sad i'm actually looking forward to going to work)

    However, when column b has a date and column a does not, it returns a value of 40,000 something. in a perfect world it would return as blank.

  5. #5
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: If and statement

    Okay that's what J.Bs' second formula does. ie. returns a blank.

    And just for the record mine adjusted
    =IF(AND(A1="",B1=""),"",IF(A1="","",IF(B1<>"",B1-A1,TODAY()-A1)))

    Go with Jerry

  6. #6
    Registered User
    Join Date
    05-21-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: If and statement

    JB's second formula did the trick. Thanks again guys! Huge help!

  7. #7
    Registered User
    Join Date
    05-21-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: If and statement

    Hey guys, I'm back.

    I went with the formula =IF(A2="", "", MIN(B2, TODAY()) - A2)

    A request just came from above asking that the formula return nothing if Column B has text in it. My brain is freezing can someone please help?

  8. #8
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: If and statement

    Do you mean that B contains "text" ( a number is OK) or "is not empty" ?

  9. #9
    Registered User
    Join Date
    05-21-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: If and statement

    I'm sorry, both column a (start date) and b (end date) contain dates. my equation is going in column c, signifying days outstanding. If column b contains a date, it is no longer outstanding. By returning the days that it was outstanding I.E. Column B-Column A it is confusing people into thinking it still is outstanding, therefore we would like it to return blank or NA.

    Make Sense?

  10. #10
    Registered User
    Join Date
    05-21-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: If and statement

    given a little more time I could figure this one out, but I'm under the gun right now, so I appreciate any help.

  11. #11
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: If and statement

    Try =IF(or(A2="",b2=""), "", MIN(B2, TODAY()) - A2)

  12. #12
    Registered User
    Join Date
    05-21-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: If and statement

    this still returns a value.

  13. #13
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: If and statement

    Care to post a small sample?

  14. #14
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: If and statement

    Maybe:

    =IF(OR(A2="", ISTEXT(B2)), "", MIN(B2, TODAY()) - A2)

  15. #15
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: If and statement

    Quote Originally Posted by tykuhn99 View Post
    My goal is to find the number of days between the two dates in column 1 and 2

    *if column 1 contains text and column 2 does not, i'd like to find the difference between todays date and column 1 date
    All of these formulas are based on your premise above, from post #1. Is this premise in error? Are you saying now:

    "If column B is empty and column A is not, I need the difference in days between today's date and the date in column A. If column B is not empty or if column A is empty, then return nothing."



    If so, then:

    =IF(OR(A2="", B2<>""), "", TODAY() - A2)

  16. #16
    Registered User
    Join Date
    05-21-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: If and statement

    Date of New Orders Date PA Received # of Days Outstanding
    8/18/10 10/19/10 (Should return 0 since PA is on file)

    12/9/10 (Blank) Should return 169 since PA not on f (Today-12/9/10)

  17. #17
    Registered User
    Join Date
    05-21-2011
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: If and statement

    Sorry for all the confusion guys, I think I have finally come up with a solution:

    "=IF(AND(A1>0,B1>0),"",IF(AND(A1=0,B1=0),"",(TODAY()-A1)))"

    I'm sure there is a much more concise way to come up with this, but I am only a beginner. Thanks again for all the help and sorry if I added to the confusion. (I too was a little confused as to what I wanted at times).

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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