+ Reply to Thread
Results 1 to 4 of 4

WEEKDAY function returning 42000+ when nested inside IF

  1. #1
    Registered User
    Join Date
    07-16-2019
    Location
    NSW, Australia
    MS-Off Ver
    2016
    Posts
    3

    Question WEEKDAY function returning 42000+ when nested inside IF

    Hi everyone! Got a fun formula here that checks the contents of specific row cells and based on their content, should output an adjusted date or a text value.

    The purpose of this formula is to show the end user, in column F (where it is down-filled from F2 in an auto-expanded table that's now up to row 51, so that's the row I copied it from) roughly when to expect a result with a standard time delay of 2 days for (in column D) a "Y", 3 days for a "N", 4 days for a "Y" if the initial date + 2 days includes a weekend day (Saturday or Sunday), and 5 days for a "N" if the initial date + 2 days includes a weekend day, because the expected work processing doesn't take place on a weekend. If the G column contains a value (that gets input by the user when they verify that the processing has taken place and would usually be a date), the F column should change its contents to "Results Received" instead of an expected date. This makes it easier on the end user, since they only need to keep an eye on F values that (using conditional formatting) turn red when the expected date is "within the last week" (to account for any days of absence by the user).

    The formula I currently have is this:

    =IF(OR(G51="",G51="N/A"),IF(E51<>"",IF(E51<>"N/A",IF(D51="Y",IF(WEEKDAY(E51+2>5),E51+4,E51+2),IF(D51="N",IF(WEEKDAY(E51+2>5),E51+5),E51+3)),"N/A"),""),"Results Received")

    E51 can have blank values because that row references a request for which processing hasn't started yet, or "N/A" because processing for that request isn't needed at all (the work has already been done before the request even came in, for instance, but the request itself still needs to be tracked).

    My problem comes from the fact that when "WEEKDAY" is referenced by itself, it returns the expected single-digit value just fine, but if nested inside an IF, it returns a value above 42000, which will always return TRUE for the ">5" test. It seems that this function is supposed to MOD(x,7) the value before returning it, but doesn't do that step if it's inside an IF. Trying to MOD it myself results in Excel telling me the formula has an error even though the added brackets etc seem to line up fine. I upgraded from Excel 2013 to 2016, but it seems that this issue followed over to the newer version. Seems like a bug, and maybe it hasn't been caught yet for patching because people usually don't stick a WEEKDAY() inside an IF()?

    There's probably a much more elegant way to achieve what I'm after as well; I've seen some very complex kludge formulas reduced to beautiful, elegant snippets; maybe the same can be done here

    Advice and assistance are welcomed!

    -Ginger-
    Last edited by Gingercat; 07-16-2019 at 07:53 PM. Reason: clarifying

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: WEEKDAY function returning 42000+ when nested inside IF

    Just format the result as a date.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    07-16-2019
    Location
    NSW, Australia
    MS-Off Ver
    2016
    Posts
    3

    Re: WEEKDAY function returning 42000+ when nested inside IF

    That doesn't help with trying to determine whether WEEKDAY+2 includes a weekend or not and adjusting accordingly. If it was as easy as just formatting as a date I would have done that already.

  4. #4
    Registered User
    Join Date
    07-16-2019
    Location
    NSW, Australia
    MS-Off Ver
    2016
    Posts
    3

    Re: WEEKDAY function returning 42000+ when nested inside IF

    Fixed it:

    =IF(OR(G51="",G51="N/A"),IF(E51<>"",IF(E51<>"N/A",IF(D51="Y",IF(MOD(WEEKDAY(E51),7)>4,E51+4,E51+2),IF(D51="N",IF(MOD(WEEKDAY(E51),7)>4,E51+5,E51+3))),"N/A"),""),"Scan Received")

    If anyone has a shorter, more elegant way of achieving the same outcome as this formula, I'd be very happy to see it so I can learn from it
    Last edited by Gingercat; 07-16-2019 at 08:54 PM.

+ 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] Having a problem with weekday function not returning the right day
    By Caylif in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 08-08-2017, 12:31 PM
  2. RAND function nested inside a VLOOKUP
    By SuperWhistle in forum Excel General
    Replies: 2
    Last Post: 11-04-2016, 12:58 AM
  3. Calling function inside function. (aka nested function)
    By jakopak in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-02-2015, 05:58 AM
  4. [SOLVED] Help Requested with Nested Small Function Inside Index/Match Formula
    By trandle in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-26-2015, 10:07 AM
  5. [SOLVED] Exclude Zero's from Min Function nested inside an index+Match... all within CELL funtion
    By clemsoncooz in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 08-05-2014, 05:16 PM
  6. [SOLVED] RIGHT Function nested inside of IF
    By jakeisbill in forum Excel General
    Replies: 6
    Last Post: 10-16-2012, 12:01 PM
  7. Replies: 1
    Last Post: 10-02-2012, 04:27 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