Lookup within a lookup?

odonnela

New Member
Joined
Aug 4, 2003
Messages
18
This is a different, more advanced, twist on a question I asked a few weeks ago. I'm curious if there is a way to look up values within a range, when the range is unspecified. It has to do with my "Offset Lookup" question -- here's the problem I posed before: http://www.mrexcel.com/board2/viewtopic.php?t=73889&highlight=

Here's the new twist: Suppose I have two sheets again -- a Data sheet and an Output sheet. The data sheet looks something like this:

Type / # / Grade
1 / 75 / Z
1 / 25 / Y
1 / 50 / X
2 / 25 / W
2 / 50 / V
2 / 75 / U
2 / 100 / T
3 / 50 / S
3 / 25 / R
3 / 75 / Q

Sorry the columns are somewhat hard to see -- basically, I have three columns and nine rows of data, with a header on top. So here's what I want to do -- I want to be able to have excel return the grade of Type 2, #75 (="U"), or Type 3, #25 (="R"), or I want it to tell me that there is no Type 1, #100. This is simple a lookup within a lookup. Sometimes the order of the "Types" may be mixed around -- I'm just curious if there's a way to lookup within a lookup to have excel look at two things: for example, is there a Type 2 in the list? If no, return "NA," if yes, is there a #50 within the Type 2's? If no, return "NA," if yes, return the Grade (e.g. "V").

Hopefully this is a erlatively easy cencept to understand. If someone does have an answer for the looku within the lookup, I have one more question -- do I have to sort by type? In other words, do all of my types (e.g. 2's) have to be together, or even in ascending order? Or could I mix the rows around and have excel see if there is, in fact a Type 2 with a #50 somewhere in the list.

Thanks for your help!
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I don't think you need to do a double vlookup. Since you have both pieces of data on the orginal table, you should be able to do this.
Setup you data table

175 Z
150 Y
125 X
275 W
250 V
Etc..(I know the number arn't correct, but this is an example)

Your vlookup should look like this
=Vlookup(B1&D1, Data, 2,false)
B1 & D1 being the cell values you are doing the search on.
This will give you the result you are looking for.

The vlookup within a vlookup would be needed if you had say 30 number grouping that you wanted down to 5 categories, and then based on the returned value and another table value do a second vlookup.
 
Upvote 0
As is, a more xpensive array formula
Book1
ABCDEFG
1Type#GradeType#Grade
2175Z275U
3125Y
4150X
5225W
6250V
7275U
82100T
9350S
10325R
11375Q
Sheet1


In G2: =INDEX(C2:C11,MATCH(E2&CHAR(127)&F2,A2:A11&CHAR(127)&B2:B11,0),0)

Which must be entered via CONTROL+SHIFT+Enter.
 
Upvote 0
I tried that, but it didn't seem to work -- maybe I'm doing something incorrect? I'm very familiar with things like VLOOKUP. Here's the test example I did (I know it doesn't paste correctly, but try to follow along):

1 25 A 2 75 #N/A
1 50 B
1 75 C
2 50 D
2 75 E
2 25 F
3 75 G
3 25 H
3 50 I

There are six columns of data. Columns 4 and 5 are what I'm looking for -- column 6 is the VLOOKUP, which came up as "#N/A." To reiterate, I'm looking to match what's in colums 4 and 5 with waht's in colums 1 and 2 to give me what's in coumn 3. The VLOOKUP function I attempted to use to accomplish this (based on your post) was: =VLOOKUP(D1&E1,$A$1:$C$9,3,FALSE)

Any thoughts on what went wrong? Is there another solution? Thanks!
 
Upvote 0
Any thoughts on what went wrong?

Don't believe you can use concatenation with VLOOKUP as you can with INDEX/MATCH -- See Aladin's posting above if you can manage an extra column, mine if you cannot.
 
Upvote 0
You need to be careful with hidden spaces, formating of both the source and lookup cells. Try changing your vlookup to
=Vlookup(trim(D1)&trim(B1),...

This will elimate space problems on the source values. You will also need to edit the cells in the lookup table and make sure there are no leading or trailing spaces. If that doesn't work, try using the text to columns tool to make sure the formatting is all the same for the data.

Hope this helps.

PS- You can use conotation in a vlookup for the lookup value, I've done it many times. The lookup table must also have the conotated value in it
ie..
B1 & C1 in column A in the vlookup table to create the unique lookup value.
 
Upvote 0
Cbrine said:
...You can use conotation in a vlookup for the lookup value, I've done it many times. The lookup table must also have the conotated value in it
ie..
B1 & C1 in column A in the vlookup table to create the unique lookup value.

That's not good enough for you cannot distinguish pairs like

1 12

11 2

after a concatenation with simply

=B1&C1
 
Upvote 0
True enough, although I've never yet encountered a situation like that yet. If I did, then I would be posting to the board for a solution.:-) Or be using the index-match solution.
 
Upvote 0
Cbrine said:
True enough, although I've never yet encountered a situation like that yet. If I did, then I would be posting to the board for a solution.:-) Or be using the index-match solution.

Just to make sure: It's not an issue of Vlookup vs Index/Match. Concatenation without a separator is the issue. The errors due to concatenation without an improbable separator can easily go undedected.
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,696
Members
452,938
Latest member
babeneker

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