简体   繁体   中英

Returning value of matching cell in a dynamically changing range with formulas?

After hours of searching and trying I have conceded defeat and ask the wisdom of this community for help.

The Goal:
- Match Customer ID and return Value 1 and Value 2 for each date range. (area in red box)

Restrictions keeping me for getting an easy solution:
- Data cannot be modified in any way (area in black box), It is in another sheet and cannot have helper columns added to it
- Data is separated by a header that is constant with only date range changing, however data is dynamic in length
- Macros are not allowed on this worksheet, so solution must be a formula

Current angle of attack (for cell H2 only) :

=VLOOKUP(G1,("B"&(MATCH(G2,B:B,0)+ROW(B:B)-1)&":"&"D"&(MATCH(G3,B:B,0)+ROW(B:B)-1)),2,FALSE)


This tries to define the Vlookup range by matching the dates and inserting the found row numbers.
=("B"&(MATCH(G2,B:B,0)+ROW(B:B)-1)&":"&"D"&(MATCH(G3,B:B,0)+ROW(B:B)-1))
returns the correct range, but when it is inserted into the range target of Vlookup I get a Value Error. Another failing is that it would not work for the last section of data as it will be missing an end header with date.

Bellow is a very simplified version of the data i will be working with:

在此处输入图片说明

Thanks for any and all help on this head scratcher

If I understand your requirements correctly, what about the following to return Value1:

=VLOOKUP(G1,OFFSET(B1,MATCH(G2,B:B,0),0,IFERROR(MATCH("Dates",OFFSET(A1,MATCH(G2,B:B,0),0,COUNTA(A:A),1),0),COUNTA(A:A)),3),2,FALSE)

This uses the OFFSET function to establish your VLOOKUP range. Using the 4th and 5th parameters returns a range instead of a single cell.

Two of the MATCH functions look for the text of the date range specified in G2. The other MATCH function looks for the next instance of the text "Dates" after the G2 match; however, the IFERROR function protects the last range (since there is not another "Dates" cell) and makes the range as large as could be needed to cover the final date range.

To modify it to return Value2, change the "2" before the "FALSE" to be "3".

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