+ Reply to Thread
Results 1 to 17 of 17

Vlookup mixed with IF, looking at a date.

  1. #1
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    846

    Vlookup mixed with IF, looking at a date.

    Good evening happy campers.

    Please see attached.

    Sheet1 Cell A1 - todays date (=today() )
    C3 - (formula here)
    Sheet2 Range A:B - 'DATA'

    I would like C3 (sheet1) to show me the name from sheet 2 that is closest to the next date on sheet2 (closest to A1 Sheet1)

    Initially i thought a nested IF within Vlookup would do it but i cant get my head round it, could someone kindly turn the light on for me?

    kind regards, galvinpaddy
    Attached Files Attached Files

  2. #2
    Forum Expert dilipandey's Avatar
    Join Date
    12-05-2011
    Location
    Dubai, UAE
    MS-Off Ver
    1997 - 2016
    Posts
    8,191

    Re: Vlookup mixed with IF, looking at a date.

    Hi Glavinpaddy,


    For nearest match, you can use Vlookup with True :-
    Use below in cell C3:-

    =VLOOKUP(A1,Sheet2!A:B,2,TRUE)

    regards,
    DILIPandey

    <click on below 'star' if this helps>
    DILIPandey, Excel rMVP
    +919810929744 (India), +971528225509 (Dubai), [email protected]

  3. #3
    Forum Expert ben_hensel's Avatar
    Join Date
    01-26-2012
    Location
    Northeast USA
    MS-Off Ver
    Office 365
    Posts
    2,043

    Re: Vlookup mixed with IF, looking at a date.

    =VLOOKUP(value, matrix, num, TRUE) can be used on sorted arrays (such as you have here) to deliver the largest value that is less than or equal to the lookup... But that's not quite what you want, huh?

    I've built what I think you want using MATCH and INDEX with an IF... didn't actually use VLOOKUP, but that's just the way the cookie crumbled. (See attached).

    I used five cells, and then just stepped cell references backwards until I was only referring to sheet1!A1 and the array--and since sheet1A1 is just = TODAY(), you could replace those too, and feed this function just the array as the argument and it would automatically spit out what's closest to today. That might be pretty opaque to look at though, be warned.
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    846

    Re: Vlookup mixed with IF, looking at a date.

    Hi Both, thanks for your input
    DILIPandey - Thanks, but i would need the next name in the list, the true part of vlookup only matches the nearest.
    Ben_Hensel - thanks, works great until i input the date in A1 as the same date on Sheet2, again, i would need it to show me the next coming Name (following the date in A1)
    Apologies both, my explanation may not have been tip top blurry eyes after sitting in-front of laptop all day
    Kind Regards, galvinpaddy

  5. #5
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    846

    Re: Vlookup mixed with IF, looking at a date.

    Good morning all.

    If it is easier the formula can look at the next name in the list and show that value.

    Kind regards, galvinpaddy.

  6. #6
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Vlookup mixed with IF, looking at a date.

    Good morning to you,too.

    Would you give a try to this?

    =INDEX(Sheet2!B1:B16,MATCH(Sheet1!A1,Sheet2!A1:A16,0)+1)
    Regards

    Fotis.

    -This is my Greek whisper to Europe.

    --Remember, saying thanks only takes a second or two. Click the little star * below, to give some Rep if you think an answer deserves it.

    Advanced Excel Techniques: http://excelxor.com/

    --KISS(Keep it simple Stupid)

    --Bring them back.

    ---See about Acropolis of Athens.

    --Visit Greece.

  7. #7
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    846

    Re: Vlookup mixed with IF, looking at a date.

    Good morning Fotis,

    Thankyou for your input.
    Please see attached, i have an #N/A error.
    PLease advise

    Kind Regards, Galvinpaddy
    Attached Files Attached Files

  8. #8
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Vlookup mixed with IF, looking at a date.

    If you use this

    =IFERROR(INDEX(Sheet2!B1:B16,MATCH(Sheet1!A1,Sheet2!A1:A16,0)+1),"")

    You will get no error but also no results since your date in Sheet1!A1, does not exists in Sheet2! Column A

  9. #9
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    846

    Re: Vlookup mixed with IF, looking at a date.

    Hi, thanks fo rthe input.
    What i need is for the formula to show me the next date and/or name in the list, following on from whatever date is added into cell A1 (sheet1)

  10. #10
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Vlookup mixed with IF, looking at a date.

    I think that my formula, does this..

    If in A1 your date is 1/02/2012, which is the expected result?
    Attached Files Attached Files

  11. #11
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    846

    Re: Vlookup mixed with IF, looking at a date.

    Ho Fotis,

    Yes, your formula works fine if the date matches one from Sheet2.
    But - the date in Sheet1 A1, is set as =TODAY() so this will change according to the date it is opened, so i would then need to see the next name on the list.
    Kind regards, galvinpaddy.
    Attached Files Attached Files

  12. #12
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Vlookup mixed with IF, looking at a date.

    So, this version must works for you. Does it?

    =IFERROR(INDEX(Sheet2!B1:B16,MATCH(Sheet1!A1,Sheet2!A1:A16,1)+1),"")

  13. #13
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    846

    Re: Vlookup mixed with IF, looking at a date.

    yes, thank-you very much indeed for your help!!!!

  14. #14
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Vlookup mixed with IF, looking at a date.

    You are welcome!

    Thank for the feed back and for reb*

  15. #15
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    846

    Re: Vlookup mixed with IF, looking at a date.

    Apologies Fotis,

    I have tried to modify the formula to fit into the sheet i need it for and have failed

    I have changed your code to -
    Please Login or Register  to view this content.
    With Rota! replacing Sheet2 and Meeting! replacing sheet1, which i assumed would still work, but the cell stays blank.
    The data on sheet 2 is the same, but name1 name2 have been replaced with the peoples first & surnames.
    The date formats are the same.

    gggrrr, could i please ask for a little more help? thanks again.

  16. #16
    Forum Expert Fotis1991's Avatar
    Join Date
    10-11-2011
    Location
    Athens(The homeland of the Democracy!). Greece
    MS-Off Ver
    Excel 1997!&2003 & 2007&2010
    Posts
    13,744

    Re: Vlookup mixed with IF, looking at a date.

    ...Maybe you try to copy down the formula? In this case you have to use absolute reference($)

    Are your data like my example here?
    Attached Files Attached Files

  17. #17
    Forum Contributor
    Join Date
    11-02-2011
    Location
    Rugby, England
    MS-Off Ver
    Office 365
    Posts
    846

    Re: Vlookup mixed with IF, looking at a date.

    Hi Fotis,

    Thanks for your help

+ 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