Expiring Todayâ€”Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Conditional VLookup

Posted on 2013-12-11
Medium Priority
452 Views
How do I built a conditional Vlookup?

For example, if source cell = X, then use =VLOOKUP(F1,A1:B2000,2,FALSE)
... where I look-up values from the 2nd column from the lookup range.

However, if source cell = Y, the use =VLOOKUP(F1,A1:B2000,3,FALSE)
... where I now want to look-up values from the 3rd column

EEH
0
Question by:ExpExchHelp
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 4
• 4

LVL 33

Accepted Solution

Rob Henson earned 1000 total points
ID: 39711102
=VLOOKUP(F1,A1:B2000,IF(source=x,2,3),FALSE)
0

LVL 85

Assisted Solution

Rory Archibald earned 1000 total points
ID: 39711103
Depends on the exact situation as to what the best formula will be, but you can use something like this:

=VLOOKUP(F1,A1:B2000,IF(A1="X",2,3),FALSE)

if A1 only has X or Y.
0

Author Closing Comment

ID: 39711108
Thanks!
0

LVL 33

Expert Comment

ID: 39711113
Just noticed, the formula as described above will result in an error; A1:B2000 is only 2 columns but you are wanting to return the value from a third column, in amendment below I have changed to C2000 so that we have 3 columns.

You may also be able to use the MATCH function to return the column.

If your source cell (A1 as suggested by rorya) is the same as a column header in the data, you can find the relevant column by matching it in the header row:

=VLOOKUP(F1,A1:C2000,MATCH(A1,A1:C1,0),FALSE)

Thanks
Rob
0

Author Comment

ID: 39711417
Rob:

Thanks for chiming in... I appreciate it.

I earlier looked at the VLookup and it appeared to make sense.   However, I didn't get a chance to actually test it (busy morning).

Yes, you're right, the proposed Vlookup didn't work for me either.

- Value in A1 is a drop-down (male, female example)
- Lookup values are in K:M
- Based on the ID number, I need all 3 males OR all 3 females (again, just an example) to be shown in column D2:D5.

Please see attached XLS for illustration purposes.

Thanks for the continued help.

EEH
Book1.xls
0

LVL 33

Expert Comment

ID: 39711528
In your example, the formula would be:

=VLOOKUP(\$C2,\$J\$1:\$M\$4,IF(\$A\$1="Male",3,4),FALSE)

However, would your data set really look like the example in J1:M4?

Normally, I would expect to see a unique ID for each individual name.

Are you trying to filter your dataset based on a specific criteria, eg in your example Male or Female?

See the attached amended file. With the arrangement of Data on Suggested tab, you can then use simple column Filters or Advanced FIlter function to produce the results expected in C:D columns.

To replicate, the file should remember the Advanced Filter settings I used. I assume you are using excel 2003 going by the .xls file name. The AF wizard is in Data menu > Filter > Advanced Filter.

If version assumption is incorrect, the AF is Data tab of ribbon > Sort & Filter Group > Advanced.

1) Data area
2) Criteria
3) Destination (greyed out if copy to another location is not ticked and will filter in place).

The criteria is A1:A2, the dropdown is now in A2 because I have added a header the same as the data table in A1 which the AF function needs.

Thanks
Rob H
Copy-of-Book1.xls
0

Author Comment

ID: 39711579
Rob:

Thanks... your proposed VLookup looks great.

I agree, this would be a poor representation of data (using the male/female example).

I only used it for illustration purposes as it doesn't require any insight understanding about my process.    So, for the actual data set, I used a totally different value set (numbers only).

Applying your formula will definitely assist me in this particular work.

Again, thanks!!

EEH
0

LVL 33

Expert Comment

ID: 39711598
No worries, is this related to the Dynamic Drop Down question you also have open?
0

Author Comment

ID: 39711620
Rob - thanks.  No, this is a different problem.

EEH
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Excel can be a tricky bit of software to get your head around. Whilst youâ€™ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to dâ€¦
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calculâ€¦
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
###### Suggested Courses
Course of the Month11 days, 4 hours left to enroll