Results 1 to 8 of 8

Next date after Today()

Threaded View

  1. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531
    Not sure which you adopted but this:

    =IF(COUNTIF(H2:H10,">"&TODAY()),MIN(IF(H2:H10>TODAY(),H2:H10)),"")
    Can be broken down into 3 "BITS"

    First:

    =IF(COUNTIF(H2:H10,">"&TODAY()),do if true, do if false)
    So the above will count how many dates in the range specified exceed Today's date - the result will be an integer value between 0 and 9... it's important to note that only the value 0 equates to FALSE in XL and so it follows that should the result of the COUNTIF be anything other than 0 (1 to 9) then this equates to TRUE

    So let's assume answer is > 0*, do TRUE action, SECOND BIT, namely:
    *based on sample data shown further down

    MIN(IF(H2:H10>TODAY(),H2:H10))
    So the above is basically going through the range H2:H10 and creating an array of values, where the value of H2:H10 > TODAY that date will be added to the array, if it is <= TODAY() a Boolean of FALSE will be added to the array, so if we assume H2:H10 values of:

    H2: 1/5/09
    H3: 1/6/09
    H4: 1/13/09
    H5: 1/14/09
    H6: 1/19/09
    H7: 1/15/09
    H8: 1/22/09
    H9: 1/27/09
    H10: 1/8/09
    And a current date of 1/21 we will end up with an array of values as so:

    {FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,"1/22/09","1/27/09",FALSE)
    Note: that in the above the dates are shown in this way for illustrative purposes, in reality dates are integer values ... on 1900 date system 1/22/09 = 39835 and 1/27/09 = 39840 and these integer values are to all intents and purposes the values held in the array.

    We then run the MIN against the above array to return the lowest value from the range as this equates to the earliest date - the logicals (FALSE) will be ignored so we get Jan 22 returned.

    If today were 1/27 then the result of our initial COUNTIF would be 0, ie FALSE, in which case the FALSE action of the IF function would be actioned, THIRD BIT, namely:

    ""
    ie return blank


    If you ever need to work through a formula be sure to check out the "Evaluate Formula" option in XL which permits you to step through how a given formula is calculated -- it is a superb and often overlooked utility IMO and is handy for all users regardless of supposed expertise.
    Last edited by DonkeyOte; 01-21-2009 at 04:34 AM.

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