How to lookup a value within a specific range within an array

gguevara

New Member
Joined
Sep 3, 2014
Messages
10
Hello,

I am trying to lookup a value that resides within a specific range of cells (or Index/Match). This range is dynamic and changes in size. The beginning of this specific range starts with a known cell value and ends with another known cell value. The value I am trying to lookup is somewhere inside this specific dynamic range. However, this specific dynamic range also resides inside a larger overall array range that is also dynamic an changes in size. The size of this larger overall array range does not really matter, as long as I can find the smaller specific dynamic range within, and then lookup the value within.

The logic would be as follows:
Look in overall array A:A, and find a specific range that being with a cell containing "16S:CADETL" and ends with a cell containing "16R:CADETL". Then find and lookup cell value "A1" in order to return "YES".

I want only the "A1" within the specific range. There can be many other "A1" values within the larger overall array range, however I only want the "A1" within the smaller specific range. In other words, the "A1" can exist multiple times within the overall array range (or not), but I want only the specific "A1" within the specific range.

Here is an illustration of what I want as a result:

Excel 2010
ABCD
1Data CodesValues
216S:LINK
310X
411X
5A1NOnot this one
617X
7A1NOnot this one
819X
920X
1016R:LINK
1116S:CADETL
129X
1311X
14A1YESI want this one
1514X
1616R:CADETL
1716S:OPTN
1810X
1912X
2015X
21A1NOnot this one
2218X
2316R:OPTN

<colgroup><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Any help would be greatly appreciated.

Thanks,
ggee
 
Hello Aladin,

Actually... I was able to take your formula and rearrange it so that it looks up the original vertical raw data on sheet1. In this way I do not need to create another table in sheet2 (it is not needed).

=VLOOKUP("A1",OFFSET(INDEX(A:A,MATCH("16S:CADETL",A:A,0),0),0,0,MATCH("16R:CADETL",A:A,0)-MATCH("16S:CADETL",A:A,0)+1,2),2,FALSE)

This formula uses OFFSET in the more familiar A1 format. Whereas Hans' formula uses INDIRECT in the less familiar R1C1 format.

Thanks to both of you. Please keep an eye on this thread, as I have one more piece to work out that is related to this.
ggee
 
Upvote 0

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hello Aladin,

Actually... I was able to take your formula and rearrange it so that it looks up the original vertical raw data on sheet1. In this way I do not need to create another table in sheet2 (it is not needed).

=VLOOKUP("A1",OFFSET(INDEX(A:A,MATCH("16S:CADETL",A:A,0),0),0,0,MATCH("16R:CADETL",A:A,0)-MATCH("16S:CADETL",A:A,0)+1,2),2,FALSE)

This formula uses OFFSET in the more familiar A1 format. Whereas Hans' formula uses INDIRECT in the less familiar R1C1 format.

Thanks to both of you. Please keep an eye on this thread, as I have one more piece to work out that is related to this.
ggee

If you want to hard code the look up specifications directly in the formula, it's okay with me. But all this has does not effect any changing to the vertical data in Sheet1.

=VLOOKUP("A1",OFFSET(INDEX(Sheet1!A:A,MATCH("16S:CADETL",Sheet1!A:A,0)),0,0,MATCH("16R:CADETL",Sheet1!A:A,0)-MATCH("16S:CADETL",Sheet1!A:A,0)+1,2),2,0)

No need to modify the 0 parameter of VLOOKUP to FALSE at all.
 
Upvote 0
I need to pin point a reference cell and then define the range it is in, then vlookup inside this range

Hello,

If you are familiar with SWIFT messages (ISO-15022) you might recognize some of the text-fields in column-A (MT564 messages to be exact).

Anyways, I need a formula or set of formulas that can do the following:
First I need to find a specific text-field within column-A ("DFLT//Y"). There are similar text-fields that can exist multiple times in the overall "big-picture" range ("DFLT//N"). However, the specific "DFLT//Y" can only exist once. I need to pinpoint this "DFLT//Y" as the reference cell (this is the driving factor of what I am ultimately trying to accomplish - see below).

This "DFLT//Y" resides within a dynamic range in column-A. This dynamic range starts with 16S:CAOPTN, and ends with 16R:CAOPTN (note the difference - 16S vs. 16R). As you can see, there are multiple instances of these 16S:CAOPTN/16R:CAOPTN ranges, and each is dynamic (they can be of any size and any multiples). I have colored each range in column-A for easy illustration. So first I need to find the only "DFLT//Y" that exists, in order to determine and target the specific dynamic range it resides in (this is the second driving factor).

Once I define this specific range, I want to be able to vlookup only inside this specific range. The test is to find the lucky "A1//Y" in column-A and return the "YES" value from column-B. I have colored the vlookup range in column-B in yellow for easy illustration. You can see that it is nested besides the related green colored range.

So in other words (to put it simply), I need to zoom-in and pinpoint the "DFLT//Y" first. Then zoom-out and define it's specific range. Then stay within this specific range and scan for "A1//Y" and return the YES value.

Please be aware that the overall "big-picture" range in column-A can be of any size (dynamic). Sometimes its small, and other times its very large. Likewise, the specific ranges are also dynamic and can be of any size - as well as repeat any number of multiple times. That is why I need for the formulas to also be dynamic, and not use fixed hard-coded cell references.

Please see a screen shot of the excel example:


Excel 2010
ABCD
1Data CodesValues
216S:LINK
310//11
4A1//YY
517//XX
616R:LINK
716S:CAOPTNComments:
8CAON//11
9DFLT//NNThis is the 1st dynamic range of 16S:CAOPTN & 16R:CAOPTN pairs.
10A1//NNI don't want range because it has a "DFLT//N" inside.
1114//XX
1216R:CAOPTN
1316S:CAOPTN
14CAON//22This is the 2nd dynamic range of 16S:CAOPTN & 16R:CAOPTN pairs.
15DFLT//YYI want this target range because it has a "DFLT//Y" inside.
16A1//YYESNote: there can only ever be one instance of a DFLT//Y,
1710//XXwhich is why I want this specific range.
1814//XXThen I want to vlookup inside this range only for "A1//Y"
1917//XXand return the "YES" value.
2016R:CAOPTN
2116S:CAOPTN
22CAON//33
23DFLT//NNThis is the 1st dynamic range of 16S:CAOPTN & 16R:CAOPTN pairs.
24A1//YNI don't want range because it has a "DFLT//N" inside.
2516R:CAOPTN
2616S:CADETL
279//XX
2811//XX
29A1//NN
3014//XX
3116R:CADETL
32
Sheet1


I hope my explanation makes sense, and I hope my excel example with colors helps to illustrate what I am looking to do. I have been trying for days and nights. My head is exploding. I asked a very similar question in another post, but I do not think I explained myself correctly. So I better organized my excel example and colored illustration.

Any help will be greatly appreciated.
Thanks,
ggee
 
Last edited:
Upvote 0
Re: I need to pin point a reference cell and then define the range it is in, then vlookup inside this range

I don't supposed that we would be lucky enough that ..

a) The section in question always contains "A1//Y" in col A and
b) The "A1//Y" always came below the "DFLT//Y"?

If so, you could try the formula in D1

Otherwise, try the D2 formula.

Extend the ranges beyond row 100 to whatever is the largest you would ever need.


Excel 2010 32 bit
ABCD
1Data CodesYES
216S:LINKYES
310//11
4A1//YY
517//XX
616R:LINK
716S:CAOPTN
8CAON//11
9DFLT//NN
10A1//NN
1114//XX
1216R:CAOPTN
1316S:CAOPTN
14CAON//22
15DFLT//YY
16A1//YYES
1710//XX
1814//XX
1917//XX
2016R:CAOPTN
2116S:CAOPTN
22CAON//33
23DFLT//NN
24A1//YN
2516R:CAOPTN
2616S:CADETL
279//XX
2811//XX
29A1//NN
3014//XX
3116R:CADETL
32
Lookup
Cell Formulas
RangeFormula
D1=VLOOKUP("A1//Y",INDEX(A1:A100,MATCH("DFLT//Y",A1:A100,0)):B100,2,0)
D2=VLOOKUP("A1//Y",INDEX(A1:A100,AGGREGATE(14,6,(ROW(A1:A100)-ROW(A1)+1)/((A1:A100="16S:CAOPTN")*(ROW(A1:A100)"DFLT//Y",A1:A100,0))),1)):INDEX(B1:B100,AGGREGATE(15,6,(ROW(A1:A100)-ROW(A1)+1)/((A1:A100="16R:CAOPTN")*(ROW(A1:A100)>MATCH("DFLT//Y",A1:A100,0))),1)),2,0)
 
Last edited:
Upvote 0
Re: I need to pin point a reference cell and then define the range it is in, then vlookup inside this range

I don't supposed that we would be lucky enough that ..

a) The section in question always contains "A1//Y" in col A and
b) The "A1//Y" always came below the "DFLT//Y"?

Otherwise, try the D2 formula.

Extend the ranges beyond row 100 to whatever is the largest you would ever need.

Hello Peter,

Thank you for the quick reply.
To answer your questions above:
a) Yes, the "A1//Y" will always be in column-A. In fact, any search cell will be in column-A.
b)No, the "A1//Y" will not always be directly below the "DFLT//Y". It can be several cells below, or it can be several cell above the "DFLT//Y". But the "A1//Y" will never be outside the specific "16S:CAOPTN - DFLT//Y - 16R:CAOPTN" range (no matter what size this range is).

Your second formula in cell D2 seems to be doing the trick. I have tested it by placing the "DFLT//Y" into one of the other ranges, and then placing the "A1//Y" above or below it, but staying within that range's boundary. It is working.

I am trying to understand the formula by looking at each part of the formula (the formulas inside the formulas).
Can you please give an brief explanation of the formula? This way I can better understand it and be able to troubleshoot it or alter it in case of an issue or slight variable.

Thanks,
ggee
 
Upvote 0
gguevara,
With reference to your other thread on this issue (https://www.mrexcel.com/forum/excel...ge-then-vlookup-inside-range.html#post4746936), please don't post what is essentially the same question in multiple threads. (See Forum Rule #12 http://www.mrexcel.com/forum/board-announcements/99490-forum-rules.html & Forum Guidelines 6 & 7 https://www.mrexcel.com/forum/board-announcements/127080-guidelines-forum-use.html)

As both threads have replies, I will now merge them. This may lead to some overlap, but that's a small price to pay...
 
Upvote 0
gguevara,
With reference to your other thread on this issue (https://www.mrexcel.com/forum/excel...ge-then-vlookup-inside-range.html#post4746936), please don't post what is essentially the same question in multiple threads. (See Forum Rule #12 http://www.mrexcel.com/forum/board-announcements/99490-forum-rules.html & Forum Guidelines 6 & 7 https://www.mrexcel.com/forum/board-announcements/127080-guidelines-forum-use.html)

As both threads have replies, I will now merge them. This may lead to some overlap, but that's a small price to pay...

Merging has dropped the last question of OP and my reply along with it...

The question was:

Today, 06:00 PM #14
gguevara View Profile
View Forum Posts
Private Message
Add as Contact
New Member Join DateSep 2014Posts9
Re: How to lookup a value within a specific range within an array
Hello again,

Once again, thank you for helping me with the first formula. Essentially this first formula allows me to define the specific range within a larger overall range, and then vlookup a cell value within this specific range.

I have a second case that is similar, but the logic is somewhat in reverse (sort of):
First I need to find a specific cell-text with a specific value. This cell-text can exist multiple times in the larger overall range. However the specific value can only exist once. Therefore, this cell-text/value combination will only exist once - cell-text DFLT with a value of Y (this is the driving factor).

Once I find this DFLT=Y combination, I then want to define the specific range that it lives in. It lives within one of the 16S:CAOPTN/16R:CAOPTN pair ranges. As you can see, there are multiple 16S:CAOPTN/16R:CAOPTN pair ranges. But the specific DFLT=Y combination only lives inside one of these pair ranges. I have been trying to pin point the DFLT=Y reference, then use OFFSET in an upward direction until it intersects with 16S:CAOPTN and downward until it intersects with 16R:CAOPTN. This would be the start and end of the specific range.

Once I define this specific range (that houses the specific DFLT=Y combination), I want to be able to vlookup inside this specific range and find my lucky "A1" and return the YES value.

In other words (putting it simply), I need to zoom-in and pinpoint the DFLT=Y first. Then zoom-out and define it's range residence. Then stay within this range and scan for "A1" and return YES.

Please see a screen shot of the excel example: [...]

Row\Col
A​
B​
1​
Data CodesValues
2​
16S:LINK
3​
10
X
4​
A1NO
5​
17
X
6​
16R:LINK
7​
16S:CAOPTN
8​
CAON
1
9​
DFLTN
10​
A1NO
11​
14
X
12​
16R:CAOPTN
13​
16S:CAOPTN
14​
CAON
2
15​
DFLTY
16​
A1YES
17​
10
X
18​
13
X
19​
17
X
20​
16R:CAOPTN
21​
16S:CAOPTN
22​
CAON
3
23​
DFLTN
24​
A1NO
25​
16R:CAOPTN
26​
16S:CADETL
27​
9
X
28​
11
X
29​
A1NO
30​
14
X
31​
16R:CADETL

My single formula answer (in line with OP's desire) was:

=VLOOKUP("A1",OFFSET($A$2,MAX(IF(MATCH(1,IF($A$2:$A$31="DFLT",IF($B$2:$B$31="Y",1)),0)>IF($A$2:$A$31="16S:CAOPTN",ROW($A$2:$A$31)-ROW($A$2)+1),ROW($A$2:$A$31)-ROW($A$2)+1)),0,MIN(IF($A$2:$A$31="16R:CAOPTN",IF(ROW($A$2:$A$31)-ROW($A$2)+1>MATCH(1,IF($A$2:$A$31="DFLT",IF($B$2:$B$31="Y",1)),0),ROW($A$2:$A$31)-ROW($A$2)+1)))-MAX(IF(MATCH(1,IF($A$2:$A$31="DFLT",IF($B$2:$B$31="Y",1)),0)>IF($A$2:$A$31="16S:CAOPTN",ROW($A$2:$A$31)-ROW($A$2)+1),ROW($A$2:$A$31)-ROW($A$2)+1)),2),2,0)
 
Upvote 0
Re: I need to pin point a reference cell and then define the range it is in, then vlookup inside this range

Can you please give an brief explanation of the formula?
The first AGGREGATE finds the largest row in the column A range where both the following conditions are true:
- The cell contains "16S:CAOPTN"
- The row is above (ie < ) the "DFLT//Y" row

For the post #14 layout that returns 13

The second AGGREGATE finds the smallest row in the column A range where both the following conditions are true:
- The cell contains "16R:CAOPTN"
- The row is below (ie > ) the "DFLT//Y" row

For the post #14 layout that returns 20

So the formula becomes
=VLOOKUP("A1//Y",INDEX(A1:A100,13):INDEX(B1:B100,20),2,0)
and therefore
=VLOOKUP("A1//Y",A13:B20,2,0)
 
Last edited:
Upvote 0
One further point.
IF "A1//Y" always exists in the "DFLT//Y" range in question (A13:A20 in the post #14 example) the the formula can be reduced to:

Code:
=VLOOKUP("A1//Y",INDEX(A1:A100,AGGREGATE(14,6,(ROW(A1:A100)-ROW(A1)+1)/((A1:A100="16S:CAOPTN")*(ROW(A1:A100)<MATCH("DFLT//Y",A1:A100,0))),1)):B100,2,0)
 
Upvote 0

Forum statistics

Threads
1,216,376
Messages
6,130,257
Members
449,568
Latest member
mwl_y

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