Lookup Match Function with Variable Dates

ShaunF

Board Regular
Joined
Jan 17, 2015
Messages
56
Hi,

Hoping someone can assist with a formula to assist with a worksheet.

On SHEET 1, I have two relevant columns 'ID' and 'DATE'. For example -

[TABLE="width: 155"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD="align: center"]ID[/TD]
[TD="align: center"]
Date​
[/TD]
[/TR]
[TR]
[TD="align: right"]465260[/TD]
[TD="align: right"]
16/08/18​
[/TD]
[/TR]
[TR]
[TD="align: right"]465260[/TD]
[TD="align: right"]03/09/18[/TD]
[/TR]
[TR]
[TD="align: right"]465260[/TD]
[TD="align: right"]04/09/18[/TD]
[/TR]
[TR]
[TD="align: right"]2859809[/TD]
[TD="align: right"]20/09/18[/TD]
[/TR]
[TR]
[TD="align: right"]2859809[/TD]
[TD="align: right"]21/09/18[/TD]
[/TR]
[TR]
[TD="align: right"]2859809[/TD]
[TD="align: right"]26/09/18[/TD]
[/TR]
[TR]
[TD="align: right"]3066409[/TD]
[TD="align: right"]23/08/18[/TD]
[/TR]
[TR]
[TD="align: right"]7105709[/TD]
[TD="align: right"]21/09/18[/TD]
[/TR]
[TR]
[TD="align: right"]7105709[/TD]
[TD="align: right"]24/09/18[/TD]
[/TR]
[TR]
[TD="align: right"]13111509[/TD]
[TD="align: right"]27/08/18[/TD]
[/TR]
</tbody>[/TABLE]


On SHEET 2, I have three relevant columns 'ID' ; 'DATE' ; 'RESULT'. For example -

[TABLE="width: 281"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD="align: center"]ID[/TD]
[TD]
DATE​
[/TD]
[TD]
RESULT​
[/TD]
[/TR]
[TR]
[TD="align: right"]
465260​
[/TD]
[TD="align: right"]
06/09/2018​
[/TD]
[TD]
ATT​
[/TD]
[/TR]
[TR]
[TD="align: right"]
146040008​
[/TD]
[TD="align: right"]
28/08/2018​
[/TD]
[TD]
DNAI​
[/TD]
[/TR]
[TR]
[TD="align: right"]
183694709​
[/TD]
[TD="align: right"]
30/09/2018​
[/TD]
[TD]
DNAD​
[/TD]
[/TR]
[TR]
[TD="align: right"]
259730008​
[/TD]
[TD="align: right"]
23/08/2018​
[/TD]
[TD]
NRE​
[/TD]
[/TR]
[TR]
[TD="align: right"]


[/TD]
[TD="align: right"][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
What I am after is a formula, which tells me:

Use the ID and DATE from Sheet 1. If it finds a result in Sheet 2, where the ID is the same and the DATE is within the next 14 DAYS then return the RESULT. If no match found, then NIL.

In the above example, the second and third rows of Sheet 1 would return a result of ATT. The rest would be NIL.

Thanks,

Shaun.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
If that Sheet2 data is in A1:C5, then try this, copied down.

Excel Workbook
ABC
1IDDate
246526016/08/2018 
34652603/09/2018ATT
44652604/09/2018ATT
5285980920/09/2018
6285980921/09/2018
7285980926/09/2018
8306640923/08/2018
9710570921/09/2018
10710570924/09/2018
111311150927/08/2018
Sheet1
 
Upvote 0
Hi Peter,

Thanks for your help. Much appreciated.

When I use your formula it returns an error - You've entered too many arguments for this function.

Any ideas?

Thanks.
 
Upvote 0
Hi Peter,

Thanks for your help. Much appreciated.

When I use your formula it returns an error - You've entered too many arguments for this function.

Any ideas?

Thanks.
Did you copy/paste my formula from the forum, or re-type it yourself?
Have you tried to modify it for your use? In doing that perhaps you have accidentally added/removed a "," or something?

If you click OK to that message does it highlight one particular part of the formula?

Suggest setting up a fresh workbook with only this sample data and layout and copy/paste the formula from the forum to show 'proof of concept'.

I have pasted my actual sheet so you can see that it is working here. :)
 
Last edited:
Upvote 0
In C2 of Sheet1 control+shift+enter, not just enter, and copy down:

=IFERROR(INDEX(Sheet2!$C$2:$C$5,MIN(IF(Sheet2!$A$2:$A$5=$A2,IF(Sheet2!$B$2:$B$5<=$B2+14,ROW(Sheet2!$A$2:$C$5)-ROW(INDEX(Sheet2!$A$2:$C$5,1,1))+1,9.99E+307),9.99E+307))),"")
 
Upvote 0
Hi Peter,

Strange indeed. I have triple-checked everything. When pressing OK it highlights the '1' right towards the end of your formula.

Thanks.
 
Upvote 0
Hi Aladin,

Thanks for your help. Formula works well - however, it is bringing through results where the date is less than the date in Sheet 1. The date must be within the next 14 days (not including the actual date).

Any ideas?

Thanks,

Shaun.
 
Upvote 0
Hi Aladin,

Thanks for your help. Formula works well - however, it is bringing through results where the date is less than the date in Sheet 1. The date must be within the next 14 days (not including the actual date).

Any ideas?

Thanks,

Shaun.

Control+shift+enter:

=IFERROR(INDEX(Sheet2!$C$2:$C$5,MIN(IF(Sheet2!$A$2:$A$5=$A2,IF((Sheet2!$B$2:$B$5>$B2)*(Sheet2!$B$2:$B$5<=$B2+14),ROW(Sheet2!$A$2:$C$5)-ROW(INDEX(Sheet2!$A$2:$C$5,1,1))+1,9.99E+307),9.99E+307))),"")
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top