+ Reply to Thread
Results 1 to 10 of 10

IF ODD date, false, If EVEN date, ok

  1. #1
    Registered User
    Join Date
    11-10-2009
    Location
    China
    MS-Off Ver
    Excel 2003
    Posts
    25

    IF ODD date, false, If EVEN date, ok

    In Excel 2003, I have a list of dates, which part of a train timetable. The train only departs on EVEN dates and arrives at its' destination the following day.

    In A1 I have a date, 1-1-2010, for example.
    In A2, I want to check the date in A1, if it is ODD, then return FALSE, if it is EVEN, then show that date +1.

    What do I mean by ODD/EVEN? With 31 days in the month, 1st, 3rd, 5th .. 31st are ODD, and 2nd, 4th .. 30th are EVEN.

    I have used this formula successfully, but there is an imposed limit of 7 nested arguments:
    =IF(A$1=1,"FALSE",IF(A$1=2,A$1+1,IF(A$1=3,"FALSE",IF(A$1=4,A$1+1,IF(A$1=5,"FALSE",IF(A$1=6,A$1+1,IF(A$1=7,"FALSE",IF(A$1=8,A$1+1))))))))

    Because of the limitations with Excel 2003 I can not grow this formula for all 31 days.

    Is there a way to simplify the formula?

    Many thanks for your help!
    Andy
    Last edited by yesmaybe; 11-12-2009 at 10:35 AM. Reason: solved

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: IF ODD date, false, If EVEN date, ok

    Try

    =IF(MOD($A1,2)=0,$A1+1,FALSE)
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    11-10-2009
    Location
    China
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: IF ODD date, false, If EVEN date, ok

    Hi!

    Thanks for the fast response. It seems to work, but isn't accurate. Can you explain what the formula is doing?

    Your formula returns 'true' on 14-01-10, and 28-01-10 which is accurate. It returns FALSE on 21-01-10 which is also accurate, but returns FALSE on 04-02-10 which is the wrong answer. 04-02-10 is an EVEN date and so should return TRUE.

    Actually, I think I may have made a mistake in my original formula and was editing it as you replied!

    Currently I am using this formula below:
    =OR(DAY(A$1)=2,DAY(A$1)=4,DAY(A$1)=6,DAY(A$1)=8,DAY(A$1)=10,DAY(A$1)=12,DAY(A$1)=14,DAY(A$1)=16,DAY(A$1)=18,DAY(A$1)=20,DAY(A$1)=22,DAY(A$1)=24,DAY(A$1)=26,DAY(A$1)=28,DAY(A$1)=30)

    This uses the DAY argument and I think that is probably important so excel knows to read the date as a date, not as a number.

    This OR formula returns TRUE if EVEN, FALSE if not (ODD). But I want to change the TRUE to a calculation and believe the OR function is limited in that way:

    Does that make any sense?!
    Andy

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: IF ODD date, false, If EVEN date, ok

    Your first sample formula did not show that you are working with dates... I assumed you had separated it out....

    Try

    =IF(MOD(DAY($A1),2)=0,$A1+1,FALSE)

    MOD() returns the remainder after a value has been divided by a divisor (2, in this case)... so if remainder is 0, then it is Even.

  5. #5
    Registered User
    Join Date
    11-10-2009
    Location
    China
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: IF ODD date, false, If EVEN date, ok

    I have played with your answer and added the DAY function.

    =IF(MOD(DAY($A1),2)=0,$A1+1,FALSE)

    That works now. Thanks for pointing me towards the MOD function.

    Andy

  6. #6
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: IF ODD date, false, If EVEN date, ok

    Great!

    Now, if you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  7. #7
    Registered User
    Join Date
    11-10-2009
    Location
    China
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: IF ODD date, false, If EVEN date, ok

    It's that time of the year again, I am updating timetables and I need a recap on the Excel formulas I learned last year!

    I have this formula, which checks if the day is a TUESDAY and gives IF TRUE, IF FALSE.

    =IF(MOD(DAY(A1,2)=2,A1+4,A1+3)

    How would I add to this, for a choice of two DAYS? So if A1 = TUES (2), +4, if A1 = SAT (6), +3, ELSE, ERROR?

    Thanks!
    Andy

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: IF ODD date, false, If EVEN date, ok

    Quote Originally Posted by yesmaybe
    if A1 = TUES (2), +4, if A1 = SAT (6), +3, ELSE, ERROR
    Do you really want an error ?

    Assuming you do...

    Please Login or Register  to view this content.
    that would generate an #N/A error for any other weekdays.

  9. #9
    Registered User
    Join Date
    11-10-2009
    Location
    China
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: IF ODD date, false, If EVEN date, ok

    thanks for the speedy reply. that works. The VLookup is a new one to me, I like it.

    Actually, Excel week starts on a Sunday, so I changed it to, is that the reasoning?
    =A1+VLOOKUP(WEEKDAY(A1,3),{2,4;6,3},2,0)

    Can you please explain what the (A1,3) and the ,2,0) means in this code?

    Thanks!
    Andy

  10. #10
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: IF ODD date, false, If EVEN date, ok

    Quote Originally Posted by yesmaybe
    Actually, Excel week starts on a Sunday
    The start of the week is determined by the (optional) return_type specified in the WEEKDAY function - the settings for which are:

    1: Sunday is Day 1 (default if not specified)
    2: Monday is Day 1
    3: Monday is Day 0 and Sunday is Day 6
    In Excel 2010 there are further options to the above

    In the example posted I used a return_type of 2 (Monday is 1) ergo Tuesday is 2 and Saturday is 6.

    For more help on WEEKDAY and VLOOKUP please see XL Help.

+ 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