简体   繁体   中英

How Might I set the Lookup Value to a date range for VLOOKUP?

在此处输入图片说明

Hi, I am trying to obtain the value of X,Y and Z by matching the tender closing date in cell G2 with vlookup.

However, I am truly lost because it returned #n/a.

Anybody knows what could be done?

You cannot use VLOOKUP to match columns to the left, you could however use INDEX. With t he example you put in the question enter in cell G3:

=INDEX(A3:A10,MATCH(G2,E3:E10,0))

Then you should get the 'x' value relating to a tender that ended on the date entered in cell G2. You can then replicate changing the first range in INDEX to columns B and C for the respective y and z values.

Bear in mind that INDEX is the same as VLOOKUP in that it will only return the first value, if two tenders finished on the same day it will only return the first it comes across, if you have more than one maybe SUMIF would work better, maybe along side COUNTIF to show how many there were.

EDIT - Further Request for Multiple Columns

If you want to match the start AND end date you need to use an array formula as below, where the start date you are looking for is in cell G2 asd the end date in cell G3:

=INDEX(A3:A10,MATCH(1,(G2=D3:D10)*(G3=E3:E10),0))

NOTE This is an array formula so when you have typed the formula you need to press Ctrl + Shift + Enter, not just enter .

With this method it is checking two criteria for true/ false (1 and 0 respectively) so it checks each row and if columns D and E match your criteria it does 1*1 and matches the criteria of 1 that you entered. Any other combination would equal 0, eg if column D matched but E didn't then 1*0 = 0, if neither matched then 0*0 = 0.

Using this you can then extend your lookup, changing the * to a + would return the first row where EITHER column matched the criteria:

=INDEX(A3:A10,MATCH(1,(G2=D3:D10)+(G3=E3:E10),0))

You can add further columns in to the criteria using the the same method, I'm not sure what the limit is.

I understand that you aren't matching the date in G2 exactly , you simply need to get the range in which it fits. To do that and return the correct "x", "y" or "z" value you can use LOOKUP , eg to get "x" value

=LOOKUP(G2,D3:D10,A3:A10)

That will give you 96.50 for your example data

change the A3:A10 range to B3:B10 or C3:C10 for "y" and "z" values respectively

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM