+ Reply to Thread
Results 1 to 7 of 7

Finding the nearest day

  1. #1
    Registered User
    Join Date
    10-16-2009
    Location
    Moscow
    MS-Off Ver
    Excel 365
    Posts
    39

    Finding the nearest day

    Hello guys!

    Sometimes I need to calculate different coefficients and ratios for the specified period (only weekdays).
    To do this, I usually enter manually starting and ending date in the cells. But due to the fact that I have only weekdays I periodically get an error #N/A, because there is no such date in my sample (for example it was a day off and i skipped it).

    I wonder, if there is a way in Excel to give a hint what is the nearest day to that I entered manually so I don't have to scroll down my sample to find it visually.

    Please, take a look at the attached file.

    Thanks in advance.
    Attached Files Attached Files

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Finding the nearest day

    Hi,

    Just leave out the ,0 bit of the Match() function. This will return the day before the day selected. if you want the day after just add a +1. Of course since you'll now always find a Match there's no need for an IF(ISERROR()) test.

    i.e.

    Please Login or Register  to view this content.
    or leave out the +1 for the day before.

    HTH
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    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
    44,371

    Re: Finding the nearest day

    Try changing the match option from 01 to 1

    =IF(ISERROR(MATCH($J$7,$C:$C,1)),"Jan22 is a Day Off, ...???",INDEX($E:$E,MATCH(J3,$C:$C,1)))

    21/01/2005
    9889.46 21/01/2005


    22/01/2005
    9889.46 21/01/2005


    23/01/2005
    9889.46 21/01/2005


    24/01/2005
    9946 24/01/2005


    25/01/2005
    9996.66 25/01/2005
    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


  4. #4
    Registered User
    Join Date
    10-16-2009
    Location
    Moscow
    MS-Off Ver
    Excel 365
    Posts
    39

    Re: Finding the nearest day

    Thank you for your replies guys.
    But that is a little bit not what I want.
    The main variable in my case is date. I'd like Excel to automatically change the date to the nearest or if it is impossible to get a message in cell J8 (in my example) something like "DayOff, The nearest date is...".

    Is it possible?
    Anyway, thanks again.

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Finding the nearest day

    Hi,

    In that case in J8

    Please Login or Register  to view this content.
    Rgds

  6. #6
    Registered User
    Join Date
    10-16-2009
    Location
    Moscow
    MS-Off Ver
    Excel 365
    Posts
    39

    Re: Finding the nearest day

    Thank you for your reply. Great idea, but your code and some modifications of it always return empty cell ("").
    I tried only that portion of code
    Please Login or Register  to view this content.
    and I see that nothing happens when I enter the date which is not in my sample, for example 22.01.05.

    Do you have any ideas on this?
    Thanks

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Finding the nearest day

    Hi,

    First you're missing a close parentheses after the '1', and the date needs to be entered with a '/' separator not a '.'

    Correct those and you'll get the result 21/01/05

    Rgds

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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