Using 'vlookup' on Multiple Criteria, with 1 Criteria being a range of possible values

KayTannee

New Member
Joined
Jan 11, 2012
Messages
23
I've tried searching around for an answer to this for awhile but with no luck.

Currently using, Excel 2007 on a Windows XP system.

Essentially, I have data as below

Code:
[FONT=Courier New]Sheet1[/FONT]
[FONT=Courier New]ID Num1.  Date           Id Num2[/FONT]
[FONT=Courier New]PM001     03/01/2012[/FONT]
[FONT=Courier New]PM002     06/01/2012[/FONT]
[FONT=Courier New]PM003     09/01/2012[/FONT]
[FONT=Courier New]PM001     02/02/2012[/FONT]
[FONT=Courier New]PM002     09/02/2012[/FONT]
[FONT=Courier New]PM003     12/02/2012[/FONT]

Code:
[FONT=Courier New]Sheet2[/FONT]
[FONT=Courier New]ID Num1.  Date            Id Num2[/FONT]
[FONT=Courier New]PM001     02/01/2012      2147[/FONT]
[FONT=Courier New]PM002     06/01/2012      2527[/FONT]
[FONT=Courier New]PM003     07/01/2012      2767[/FONT]
[FONT=Courier New]PM001     02/02/2012      2165[/FONT]
[FONT=Courier New]PM002     10/02/2012      2321[/FONT]
[FONT=Courier New]PM003     11/02/2012      2854[/FONT]

So, I'm trying to 'VLOOKUP' the ID Num2 value, accross to Sheet1. Based upon the ID Num1 and the date, but the date can be a couple of days different. I would strip the days, so just looking up the Month / Year value, but I can't do this because some ID Nums weekly, but none are under a week frequency. So I want a 6 day margin for range.

As far as I've got so far is the below formula,
Code:
{=INDEX(Sheet2!$C$2:$C$7,MATCH(1,(Sheet2!$A$2:$A$7=$A2)*(Sheet2!$B$2:$B$7=$B2),0))}

The issue is, that this only matches if the dates are exactly the same. What I require is a few days give or take.

I've attempted this, basically throwing in a AND Lower and Higher 3 days. It's not having it though.

Code:
{=INDEX(Sheet2!$C$2:$C$7,MATCH(1,(Sheet2!$A$2:$A$7=$A2)*(AND(Sheet2!$B$2:$B$7>DATE(YEAR($B2),MONTH($B2),DAY($B2)-3),Sheet2!$B$2:$B$7<DATE(YEAR($B2),MONTH($B2),DAY($B2)+3))),0))}

/Edit :: Gah, this board is obsessed with removing half of my formula, even though in Code tags.
:(

Thank you in advance for this, I'm sure I'm close, I just don't fully understand how the array syntax should be layed out. I'm guessing its not as simple as just chucking in an AND statement.

Cheers
[/FONT]
 
Last edited:

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
I've tried searching around for an answer to this for awhile but with no luck.

Currently using, Excel 2007 on a Windows XP system.

Essentially, I have data as below


Sheet1
ID Num1. Date Id Num2
PM001 03/01/2012
PM002 06/01/2012
PM003 09/01/2012
PM001 02/02/2012
PM002 09/02/2012
PM003 12/02/2012



Sheet2
ID Num1. Date Id Num2
PM001 02/01/2012 2147
PM002 06/01/2012 2527
PM003 07/01/2012 2767
PM001 02/02/2012 2165
PM002 10/02/2012 2321
PM003 11/02/2012 2854


So, I'm trying to 'VLOOKUP' the ID Num2 value, accross to Sheet1. Based upon the ID Num1 and the date, but the date can be a couple of days different. I would strip the days, so just looking up the Month / Year value, but I can't do this because some ID Nums weekly, but none are under a week frequency. So I want a 6 day margin for range.

As far as I've got so far is the below formula,

{=INDEX(Sheet2!$C$2:$C$7,MATCH(1,(Sheet2!$A$2:$A$7=$A2)*(Sheet2!$B$2:$B$7=$B2),0))}

The issue is, that this only matches if the dates are exactly the same. What I require is a few days give or take.

I've attempted this, basically throwing in a AND Lower and Higher 3 days. It's not having it though.



{=INDEX(Sheet2!$C$2:$C$7,MATCH(1,(Sheet2!$A$2:$A$7=$A2)*(AND(Sheet2!$B$2:$B$7>DATE(YEAR($B2),MONTH($B2),DAY($B2)-3),Sheet2!$B$2:$B$7<DATE(YEAR($B2),MONTH($B2),DAY($B2)+3))),0))} p <>

/Edit :: Gah, this board is obsessed with removing half of my formula, even though in Code tags.
:(

Thank you in advance for this, I'm sure I'm close, I just don't fully understand how the array syntax should be layed out. I'm guessing its not as simple as just chucking in an AND statement.

Cheers
[/FONT]
Maybe this...

Sheet1

<TABLE style="PADDING-RIGHT: 2pt; PADDING-LEFT: 2pt; FONT-SIZE: 10pt; FONT-FAMILY: Verdana,Arial; BACKGROUND-COLOR: #ffffff" cellSpacing=0 cellPadding=0 border=0><COLGROUP><COL style="FONT-WEIGHT: bold; WIDTH: 30px"><COL style="WIDTH: 72px"><COL style="WIDTH: 81px"><COL style="WIDTH: 72px"></COLGROUP><TBODY><TR style="FONT-WEIGHT: bold; FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center"><TD> </TD><TD>A</TD><TD>B</TD><TD>C</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">2</TD><TD style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-BOTTOM: #000000 1px solid">PM001</TD><TD style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT-WIDTH: 1px; BORDER-LEFT-COLOR: #000000; BORDER-BOTTOM: #000000 1px solid; TEXT-ALIGN: right">1/3/2012</TD><TD style="BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; BORDER-LEFT-WIDTH: 1px; BORDER-LEFT-COLOR: #000000; BORDER-BOTTOM: #000000 1px solid; TEXT-ALIGN: right">2147</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">3</TD><TD style="BORDER-TOP-WIDTH: 1px; BORDER-RIGHT: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-TOP-COLOR: #000000; BORDER-BOTTOM: #000000 1px solid">PM002</TD><TD style="BORDER-TOP-WIDTH: 1px; BORDER-RIGHT: #000000 1px solid; BORDER-LEFT-WIDTH: 1px; BORDER-LEFT-COLOR: #000000; BORDER-TOP-COLOR: #000000; BORDER-BOTTOM: #000000 1px solid; TEXT-ALIGN: right">1/6/2012</TD><TD style="BORDER-TOP-WIDTH: 1px; BORDER-RIGHT: #000000 1px solid; BORDER-LEFT-WIDTH: 1px; BORDER-LEFT-COLOR: #000000; BORDER-TOP-COLOR: #000000; BORDER-BOTTOM: #000000 1px solid; TEXT-ALIGN: right">2527</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">4</TD><TD style="BORDER-TOP-WIDTH: 1px; BORDER-RIGHT: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-TOP-COLOR: #000000; BORDER-BOTTOM: #000000 1px solid">PM003</TD><TD style="BORDER-TOP-WIDTH: 1px; BORDER-RIGHT: #000000 1px solid; BORDER-LEFT-WIDTH: 1px; BORDER-LEFT-COLOR: #000000; BORDER-TOP-COLOR: #000000; BORDER-BOTTOM: #000000 1px solid; TEXT-ALIGN: right">1/9/2012</TD><TD style="BORDER-TOP-WIDTH: 1px; BORDER-RIGHT: #000000 1px solid; BORDER-LEFT-WIDTH: 1px; BORDER-LEFT-COLOR: #000000; BORDER-TOP-COLOR: #000000; BORDER-BOTTOM: #000000 1px solid; TEXT-ALIGN: right">2767</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">5</TD><TD style="BORDER-TOP-WIDTH: 1px; BORDER-RIGHT: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-TOP-COLOR: #000000; BORDER-BOTTOM: #000000 1px solid">PM001</TD><TD style="BORDER-TOP-WIDTH: 1px; BORDER-RIGHT: #000000 1px solid; BORDER-LEFT-WIDTH: 1px; BORDER-LEFT-COLOR: #000000; BORDER-TOP-COLOR: #000000; BORDER-BOTTOM: #000000 1px solid; TEXT-ALIGN: right">2/2/2012</TD><TD style="BORDER-TOP-WIDTH: 1px; BORDER-RIGHT: #000000 1px solid; BORDER-LEFT-WIDTH: 1px; BORDER-LEFT-COLOR: #000000; BORDER-TOP-COLOR: #000000; BORDER-BOTTOM: #000000 1px solid; TEXT-ALIGN: right">2165</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">6</TD><TD style="BORDER-TOP-WIDTH: 1px; BORDER-RIGHT: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-TOP-COLOR: #000000; BORDER-BOTTOM: #000000 1px solid">PM002</TD><TD style="BORDER-TOP-WIDTH: 1px; BORDER-RIGHT: #000000 1px solid; BORDER-LEFT-WIDTH: 1px; BORDER-LEFT-COLOR: #000000; BORDER-TOP-COLOR: #000000; BORDER-BOTTOM: #000000 1px solid; TEXT-ALIGN: right">2/9/2012</TD><TD style="BORDER-TOP-WIDTH: 1px; BORDER-RIGHT: #000000 1px solid; BORDER-LEFT-WIDTH: 1px; BORDER-LEFT-COLOR: #000000; BORDER-TOP-COLOR: #000000; BORDER-BOTTOM: #000000 1px solid; TEXT-ALIGN: right">2321</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">7</TD><TD style="BORDER-TOP-WIDTH: 1px; BORDER-RIGHT: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-TOP-COLOR: #000000; BORDER-BOTTOM: #000000 1px solid">PM003</TD><TD style="BORDER-TOP-WIDTH: 1px; BORDER-RIGHT: #000000 1px solid; BORDER-LEFT-WIDTH: 1px; BORDER-LEFT-COLOR: #000000; BORDER-TOP-COLOR: #000000; BORDER-BOTTOM: #000000 1px solid; TEXT-ALIGN: right">2/12/2012</TD><TD style="BORDER-TOP-WIDTH: 1px; BORDER-RIGHT: #000000 1px solid; BORDER-LEFT-WIDTH: 1px; BORDER-LEFT-COLOR: #000000; BORDER-TOP-COLOR: #000000; BORDER-BOTTOM: #000000 1px solid; TEXT-ALIGN: right">2854</TD></TR></TBODY></TABLE>


This array formula** entered in C2 and copied down:

=INDEX(Sheet2!C$2:C$7,MATCH(1,IF(Sheet2!A$2:A$7=A2,IF(Sheet2!B$2:B$7>=B2-3,IF(Sheet2!B$2:B$7<=B2+3,1))),0))

** array formulas need to be entered using the key
combination of CTRL,SHIFT,ENTER (not just ENTER).
Hold down both the CTRL key and the SHIFT key
then hit ENTER.
 
Upvote 0
That was an exceptionally quick reply, thank you so much. Works a treat!

Now going to sit down and work out why it works, definitly need to understand arrays better.

Thank you!
 
Upvote 0
That was an exceptionally quick reply, thank you so much. Works a treat!

Now going to sit down and work out why it works, definitly need to understand arrays better.

Thank you!
You're welcome. Thanks for the feedback! :cool:
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,719
Members
452,939
Latest member
WCrawford

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