Lookup a text value based on multiple conditions

noodle

New member
Joined
Jun 12, 2013
Messages
5
Reaction score
0
Points
0
I have created a spreadsheet that uses conditional drop-down menus created with data validation.

What I now want to do is have my spreadsheet populate with a code, based on what was selected in the drop-down lists. I have the list of all possible codes, but I can't figure out how to make Excel look them up. Maybe I need VBA, I really don't know.

In case my explanation is not clear, I have attached a file showing what I am trying to do. I want the C column to populate with the correct code from G16:G24. How can I acheive this?

View attachment lookup-test.xlsx

Thanks!
 

JeffreyWeir

Super Moderator
Staff member
Joined
Mar 22, 2011
Messages
357
Reaction score
0
Points
0
Location
New Zealand
You can use a simple VLOOKUP. In cell C2, put this and then copy it down:
=VLOOKUP(B2,$F$16:$G$24,2,FALSE)
 

noodle

New member
Joined
Jun 12, 2013
Messages
5
Reaction score
0
Points
0
Thanks for the reply. However it doesn't quite work with my scenario. I realize that with the dummy spreadsheet I uploaded, the "code" is different for every city, but with what I am trying to accomplish, the code is dependent on 2 or more different items. I.e., in my dummy spreadsheet, lets pretend that my code is dependent on both Country and City.

I tried adjusting the formula to:
=VLOOKUP(B2,$E$16:$G$24,2,FALSE)

So that it would also capture my Country list, but VLOOKUP doesn't like that and give me a #N/A.
 

JeffreyWeir

Super Moderator
Staff member
Joined
Mar 22, 2011
Messages
357
Reaction score
0
Points
0
Location
New Zealand
why do you need it to capture your Country list? The list of cities is unique.
 

JeffreyWeir

Super Moderator
Staff member
Joined
Mar 22, 2011
Messages
357
Reaction score
0
Points
0
Location
New Zealand
Ah, you don't want an NA in the case that they have selected a country but have yet to select a city. In that case, use this:
=IFERROR(VLOOKUP(B2,$F$16:$G$24,2,FALSE),"")
 

JoePublic

Super Moderator
Staff member
Joined
Sep 16, 2011
Messages
234
Reaction score
3
Points
18
Location
UK
Excel Version(s)
2016
If your real cities list is not unique, try:
=IFERROR(LOOKUP(2,1/($E$16:$E$24=A2)/($F$16:$F$24=B2),$G$16:$G$24),"")
 

noodle

New member
Joined
Jun 12, 2013
Messages
5
Reaction score
0
Points
0
Hi guys,

Thanks for your help. I guess the fake spreadsheet I uploaded wasn't a good example. In my real spreadsheet (which I did not want to publicly upload), the codes are unique based on both "city" and "country". (Actually, in the real thing, I want to look up G/L numbers and tax codes, based on different types of travel by different types of employees).

So lets pretend that we need to look up both country and city to get the code.

After doing some more reading, I think I have to use some kind of INDEX-MATCH method, so I am working on that...
 

JoePublic

Super Moderator
Staff member
Joined
Sep 16, 2011
Messages
234
Reaction score
3
Points
18
Location
UK
Excel Version(s)
2016
The formula I provided looks up based on both city and country.
 

noodle

New member
Joined
Jun 12, 2013
Messages
5
Reaction score
0
Points
0
Thanks, Joe! I must have done something wrong the first time I tried to use your formula. It works great. Now, I just have to get it working in my real spreadsheet, which has the lookup values on a separate sheet.... I'm sure I'll be able to figure it out though.

But I also want to understand how this formula works and have a couple of questions:

1. What does the 2,1 at the beginning refer to?

2. The formula looks to my naive eye like it uses division (/), but I realize that mustn't really be the case. What does the / do?

3. Why do we need to add a $ before each part of the cell reference?

thanks a bunch!
 

JoePublic

Super Moderator
Staff member
Joined
Sep 16, 2011
Messages
234
Reaction score
3
Points
18
Location
UK
Excel Version(s)
2016
2 is the lookup value, 1 is the value that is divided (re your point 2) by the two following arrays of TRUE/FALSE values, which are treated as 1/0 respectively and hence you end up with arrays of either 1/1 or 1/0. Fortunately LOOKUP ignores error values so only matches the last 1 value it finds (which hopefully is the only 1).
 
Top