close

Login to Excel-King.com

Please use the login boxes below to log in to my webpage. You need to login in i. e. to make sure you can post to the forums.

Log in here!

About the author

Image of Philipp Kowalski

Philipp Kowalski is a self-taught Excel-lover, project manager and blog-owner. Besides developing "beautiful" solutions in MS' premier spreadsheet tool, he loves his fiance, his cats and surfing the net. He is CEO and owner of Inservo IT, the company behind Excel-King. He's also available on Twitter and YouTube. If you like this website, please leave a comment. If you want to know more visit the forums or look into the about section of this website.

This post concludes our mini-series on MS Excel's VLOOKUP funtionality. You can see the other two posts here: Introduction to the VLOOKUP funtion Being TURE with VLOOKUP Do you know that situation? You have more than one table as your target matrix to search in. A combination of some of MSXL's functions makes it very nice and easy to search in several tables.

The functions we will use are

 

  • IF - A simple IF-function which has a logical validation, and two conditions, one for a true outcome, one for a false outcome. This is one of the most used and simplest functions in Excel
  • ISNA - This is a function out of the "Information Bucket" of MSXL's function categories. It checks wether a value is #N/A or not and returns TRUE or FALSE
  • VLOOKUP - Finally the core of our formula. As mentioned in other posts before, this function checks a target value against a matrix and then returns any given value of that matrix. It can have exact or "just" close matches. The difference between that has been explained in the articles mentioned above

Ok, let's go. Imagine, you have a workbook with three worksheets / tables like this:

Overview

  A B
1 City State
2 New York  
3 Miami  
4 Los Angeles  
5 Seattle  

East

  A B
1 City State
2 Pittsburgh PA
3 New York NY
4 Boston MA
5 Baltimore MY
6 Orlando FL
7 Miami FL
8 Charleston SC
9 Atlanta GA

West

  A B
1 City State
2 Los Angeles CA
3 San Francisco CA
4 Phoenix AZ
5 Albuquerque NM
6 Seattle WA
7 Portland OR
8 Salt-Lake-City UT

Display Excel tables online >> Excel Jeanie HTML 4

What we want to do now is to return the correct state abrreviation of either the EAST or the WEST table into our Overview worksheet. The formula looks like this:

=IF(ISNA(VLOOKUP(A2,East!$A$1:$B$9,2,FALSE)),

VLOOKUP(A2,West!$A$1:$B$8,2,FALSE),

VLOOKUP(A2,East!$A$1:$B$9,2,FALSE))

Okay, okay, I know it. It looks terrible and totally "overcrowded". But I will explain it step by step so everyone will get a clue, how it works.

IF This simply allows us to use more than one table as target matrix for our VLOOKUP. In fact they are two. If we want more than two matrices to look in, we have to nest the IF functions into one another.

ISNA(VLOOKUP(A2,East!$A$1:$B$9,2,FALSE)) This informational function will check the following validation for a value TRUE or FALSE. In our case it says in plain English:

"If you have checked for the cities in our East-Coast-table and have found nothing, then please return the value TRUE, because the question do we get a "#N/A" value is answered with yes (=TRUE). Otherwise (you have found something in our East-Coast-table) answer is with NO (=FALSE) because the returned value is not "#N/A"."

VLOOKUP(A2,West!$A$1:$B$8,2,FALSE) - The TRUE part of the IF function Okay. The answer in the ISNA question (see above) was: "Yes, we have a "#N/A" value, therefore it's TRUE". That means, we have to switch to our next table, which is in our case the West-Coast-table. There we do our VLOOKUP looking for the cities (exact match) of the OVERVIEW-table and returning the state abbreviation (column 2 of our tarhet matrix)

VLOOKUP(A2,East!$A$1:$B$9,2,FALSE) - The FALSE part of the IF function So the answer of the ISNA question (see above) was FALSE, meaning, yes we have found our city in the East-Coast-table, then please proceed with the VLOOKUP for the East-Coast-table, meaning:

  • take the city
  • look in the matrix for an exact match
  • return column 2 - the state

The result of the formula should be like this:

Overview

  A B
1 City State
2 New York NY
3 Miami FL
4 Los Angeles CA
5 Seattle WA

Display Excel tables online >> Excel Jeanie HTML 4

Once you got the concept of this formula it comes in very handy, because it allows you to look in several tables for a result. Some tips - which of course can also be applied to other formuals as well - on this method:

  1. Take care of the braces. Always make sure to close the brackets
  2. If you nest more than one IF-functions into this formula (I will post a video on how to do that in the near future), always have the matching result of the first VLOOKUP - the one that ISNA checks for - in the last argument of your initial or first IF function. This means that you should repeat the VLOOKUP of the ISNA in the last argument before the all brackets are closed.
  3. Be sure to take care of your "regional settings". As mentioned by Art in the comments section below you have to the semicolon ";" as a separator if you're working with European versions of Excel and a comma "," if you have a non-European (i. e. US) version of the software. Thank you Art for the hint! :-)

What do you think? Is that useful for your daily works? Do you have ideas, where it can be utilized? Write a comment or send me an email through my contact form.

Discuss this blog post in the forums (click the blue button)


Administrator
Written on Tuesday, 23 June 2009 00:00 by Administrator

Viewed 153 times so far.
Like this? Tweet it to your followers!

Rate this article

(0 votes)

Latest 'tweets' from Phil Kowalski

  • @jonstank hopefully you mean the tv series ;-) Link Monday, 08 March 2010 09:13
  • RT @happymakernowco Choose Happiness with Gratitude | Happy Maker Now http://bit.ly/cQgPki Link Sunday, 21 February 2010 05:12
  • RT @tweetmeme A Day Through the Eyes of a Blind Woman http://is.gd/7GTLq don't always take everything for granted!! Link Sunday, 21 February 2010 04:47
  • Spinning images http://is.gd/8ARak Link Wednesday, 17 February 2010 11:04
  • How does your Excel look like? http://is.gd/8vpph Link Tuesday, 16 February 2010 08:14

Comments  

 
0 #1 Art Johnson 2009-06-23 16:32
Very nice! This will be very helpful. Clever use of ISNA to enable the second lookup.

Once again, I can’t make this work with the semi-colon “;”, but works fine with a comma. “,”. Are you perhaps using a European version of Excel? I think the conventions are different.
Quote
 
 
0 #2 WebGenii 2009-06-23 16:51
The only additional thing I would do with a very long formula like this is to use Alt + Enter to force the formula to wrap in the cell. Doesn’t change how the formula works and makes long formulas like this easier to read.
Like this:
=IF(ISNA(
VLOOKUP(A2;East !$A$1:$B$9;2;FALSE)) ;
VLOOKUP(A2;West !$A$1:$B$8;2;FALSE);
VLOOKUP(A2;East !$A$1:$B$9;2;FALSE))

If you’ve already given this tip in previous post – oops on me
Quote
 
 
0 #3 Administrator 2009-06-23 16:52
Hi Art,

thank you for your comment. You are absolutely right with your comment. That’s one of the small things I always forget to change. I will mention it in the tips section below the post. Sorry for any inconvenience caused.
Quote
 
 
0 #4 Administrator 2009-06-23 17:02
Hi WebGenii,

cool tip. If have not mentioned it before (but should have, huh?). I will include it in a future post on tips if that’s okay for you and of course will mention your name as the one who gave it to me (Honor to whom honor is due)
Quote
 
 
0 #5 Victoria 2010-01-18 21:50
Thanks so much for this tip! I’ve never been able to use VLOOKUP with two sets of data like this.
Quote
 

Add comment


Security code
Refresh

Sign up for updates

Receive the newest blog posts directly into your inbox!

Please note, that all fields are required.

First Name
Invalid Input
Family Name
Invalid Input
Email
Please enter your email address to receive our newsletter.

Please tick the check box to make sure, that you get the newsletter.

Get my VLOOKUP mini series as PDF for FREE as a little Thank You for signing up!

Sign up for updates

Receive the newest blog posts directly into your inbox!

Please note, that all fields are required.

First Name
Invalid Input
Family Name
Invalid Input
Email
Please enter your email address to receive our newsletter.

Please tick the check box to make sure, that you get the newsletter.

Get my VLOOKUP mini series as PDF for FREE as a little Thank You for signing up!

Sharing is caring

Facebook Twitter Digg Delicious Stumbleupon Google Bookmarks RSS Feed