Link to home
Start Free TrialLog in
Avatar of ExpExchHelp
ExpExchHelpFlag for United States of America

asked on

Conditional VLookup

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
ASKER CERTIFIED SOLUTION
Avatar of Rob Henson
Rob Henson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ExpExchHelp

ASKER

Thanks!
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
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.

Please find attached XLS.  
- 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
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.

AF asks for:
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
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
No worries, is this related to the Dynamic Drop Down question you also have open?
Rob - thanks.  No, this is a different problem.

EEH