EXCEL - How To Write Perfect VLOOKUP and INDEX and MATCH Formulas

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 29

How To Pull Specific Information From Excel Tables

To professionals who love organized data

How to Write Perfect VLOOKUP/INDEX & MATCH Formulas crash course


By John Franco. First version: Dec 2011. This version: Dec 2014
Licensing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, without the prior written permission of the
publisher.
If you want to sell this book, use it for commercial purposes, distribute it in bulk quant ities in
your workplace, or a hard copy version; please Contact me
Disclaimer
The author and publisher have made every effort to ensure the accuracy of the information
herein. However, the information contained in this book is sold without warranty, either
express or implied. Neither the authors and Wizdoh.com, nor its dealers or distributors, will
be held liable for any damages to be caused either directly or indirectly by the instructions
contained in this book, or by the software or hardware products described herein.
Trademark Notice
Rather than indicating every occurrence of a trademarked name as such, this book uses the
names only in an editorial fashion and to the benefit of the trademark owner with no
intention of infringement of the trademark.
Excel is a registered trademark of Microsoft Corporation
Language disclaimer
I do my best but English is not my native language. I apologize for language errors in my
writing.

How To Pull Specific Information From Excel Tables

John Franco is someone who I worked with very closely via online collaboration for the 1st
five months of 2010. He is not only a very advanced user and instructor of Excel
spreadsheets with a true gift for thinking like Excel thinks, but also possesses the highest
degree of true entrepreneurial mindsets and understanding that one might hope to
encounter. His Blue Ocean mindset along with a deep understanding and fervent/constant
application of universal laws and principles, have set John Franco on a path to earning a
place among the worlds greatest thinkers.
John cares deeply for and is genuinely committed to the advancement of peoples
effectiveness in their chosen careers as well as the world around them in general. His
sincerity towards humanity as a whole, and our advancement in both effectiveness and
happiness is what sets him apart from many in his field. Im honored to know him as well as
I do, and would not hesitate to work with him again in any capacity. John Franco is an
Excel expert of the highest level, an entrepreneur of great effectiveness, and a proven true
friend to mankind in all facets of his life.
Jeff Stewart, Dufur, Oregon. Partner and Chief Editor,
Excel Spreadsheet Authors (my first web site)
Dear John,
Its such a nice feeling that people like you are existing on this earth. Who are willing to
teach and share whatever they are good at. Teaching with no selfish reason is the best thing
considered in India. If you give money or some material thing it will not last forever. But if
you teach something to anyone it stays permanently with that person.
So John keep up the good work. God bless you. I will be definitely follow you.
John, Its such a nice feeling that I could follow you as a subscriber. Yes you have done it
and I feel proud about it. The feeling of giving is great and you have given knowledge to
people. I wish that I could learn and be like you. I will follow you in your private

What people say about Johns teachings


entrepreneurship like a little lamb.
All the best. God bless you.
~Gautam Shastry, Jindal School of Hotel Management
John...You ARE a GREAT teacher...Thank you...
~Randy
Thanks for the clarity and metaphor.
Clayton Keirns, Pomona, California
Dear JohnI want you to know how blessed I am meeting someone like you with this craft
of yours! Its really helpful and easy to understand. Nothing more to say, Ill keep this for
life and share to my colleaguesWish you the best of everything through the years to come.
Muchas Gracias.
~Garry Pasan
Dear Dr John.
Sometimes words cannot describe well to give you what you deserve as special thanks.
Truly, You are the person who made me love Excel more and more. Your role and efforts
were as an honest guide and teacher.
Surely, I want to be with you to learn more and to make my life easier with Excel. Please
consider me one of your students forever.
Dear Mr. John
You are really a great person. People keep remembering persons make their life easier. You
are one of those person whose name should be written in a golden Ink.
I read thoroughly your sent messages and every time I learn more.
Thanks for your favor.
Regards
Dear John
Nice to hear from you. You are the person who make my way in learning Excel and Macros
programming much easier. So, many thanks for you. I really missed your articles about
Macros Programming and hope to receive more and more.
Really you are fascinating and has an explanation method that is highly attractive. Your

How To Pull Specific Information From Excel Tables


approach impressed me because hits the point directly.
~Emad Talafeha, ArabPotash.com
Good luck, to a man with a good heart and a good head!!
~Jim
Sir,
Your knowledge speaks volumes about your attainment, people like you must be few, you are
a master and socialistic personality whose aim is to be successful and creating success for
other.
Wish You all the best
~Suhail Serco, Dubai Metro
I just can't stop learning from you. Please stay "tuned" in championing intuitive Excel VBA.
Phil Egan
Thanks John. I'm always looking for new features and tricks. I like what I saw in your guide.
Yes, it was basic, but it focused on the one thing I think is overlooked. Getting the RIGHT
metric in the dashboard makes a huge difference.
Thanks a lot.
Mark Johnson

Table of contents

WHAT PEOPLE SAY ABOUT JOHNS TEACHINGS

TABLE OF CONTENTS

ABOUT JOHN FRANCO

HOW TO UNDERSTAND AND REMEMBER THE LOOKUP SYNTAX

The lookup terms demystified!

So now every lookup term makes sense...

12

VLOOKUP intuitive example

13

INDEX & MATCH intuitive example

14

HOW TO SET UP YOUR DATA TABLE FOR PERFECT MATCHES

15

Elements of a table

15

Excel tables can handle 3 types of data


Numbers
Dates
Texts

16
16
17
17

3 Donts when setting up a table


Never put the key field beyond the left (for VLOOKUP).
Never leave the key field unsorted ascending for approximate VLOOKUP or INDEX and MATCH formulas
Don't add any prefix, suffix or extra characters to a record

18
18
18
20

3 Dos when setting up a table


Use a consistent format on any given column
Use the right decimal delimiter
Enter texts correctly

20
20
21
22

HOW TO GET RID OF #N/A ERRORS ONCE FOR ALL WITH THE TIF TECHNOLOGY

23

#N/A is not an error

23

How to get genuine #N/A errors (perfect matches)

24

How to implement lookups like a professional (TIF system)

26

How To Pull Specific Information From Excel Tables

I believe Excel empowers us to express our creativity at work, life and


business, and the more you understand it, the more you enjoy working with
data and information, and the more things you can do (with less effort).

am John Franco, Excel author of many books like How to


write Excel macros from scratch, Understanding Pivot Tables
mechanics, How to design Excel dashboards, How to record
Excel macros that work, and many more. Since 2009, I have
been teaching Excel in a
,
way,
using explanations that make sense so you apply Excel tools
and tricks to your own context.
During this time, I have served to more than 10000
subscribers and more than 1000 customers.
I unified all my Excel websites into Wizdoh.com, an online
training portal dedicated to make you
I worked as a Civil Engineer for 8 years, for one of the 25 th biggest construction
companies in the world. At that time I worked under a very stern boss. He was
from Brazil, and he was VERY particular in the way he wanted things done. He
was also considered an Excel god! He could do things with a spreadsheet that
I never even knew were possible!
And because of HIS expertise, he required a lot out of ME. So this forced me to
learn how to become a guru myself. Its true that when you surround yourself
with people who are better than you at something, YOU become better in the
process!
Know my full Excel story here
Thanks

Email me at: john@wizdoh.com Find the education you need to Understand


Excel More at: http://www.wizdoh.com

How to understand and remember the lookup syntax

Computer science is no more about computers than astronomy is about


telescopes.
Edsger Dijkstra

ow you will truly understand and remember the syntax of


VLOOKUP/INDEX & MATCH.
Let's start...

First, let me ask you a question...


How do you find the phone number of your favorite actor?
This is the first thing you
have in mind when you start a search, right?

How To Pull Specific Information From Excel Tables


But you want to know something about someone; in other words, you want to
know what you don't know, right? On this case, you want to know the phone
number of Harrison Ford so

Also, you need a place where the information is located, right?

So you need a list with names and phones. This list (phone directory) can be in
paper, in a cell phone, in a digital .pdf file, etc. And you need to find the exact
phone number and not everyone else's number (what to return)

10

How to understand and remember the lookup syntax


You want to call Harrison Ford so you don't want anybody else's number. You
want the exact number in the list.
And you need some tool to scan the list and detect the exact record you are
looking for. You can use your index finger or a pointer.
You need a pointer that helps you find the person's name and also his phone
number on any adjacent column.

So the 4 natural lookup elements are:

What you know (Harrison Ford)

What you don't know and are eager to know (Harrison Ford's phone
number)

Where should it be (where should the unknown stuff be - phone directory)

What to return (exact or approximate phone number)

In a moment you will learn that these 4 terms exist always in any lookup
formula...
Now we can redefine the lookup terms...
What you know = Search value

You have always a search value; you cannot look at a table without this value in
mind; it's pointless.
Where should it be = Source table

You need a reliable list of data. This table should contain a column with the
values you know and other columns with the values you don't know.
What you dont know and are eager to know = Column with the data you want

The source list should contain columns with the information you don't know
11

How To Pull Specific Information From Excel Tables


and are eager to know. These columns are usually called attribute columns.
What to return = Matching type

You need to specify beforehand if you want an exact match or an approximate


one.
And the pointer = LOOKUP formula

And you need a tool to search and find the value you know and then to pick the
unknown info at some adjacent attribute column. This tool can be your eyes,
your index finger, a pointer, etc.
In Excel you use a lookup formula as a pointer (VLOOKUP or MATCH).

This is the VLOOKUP syntax...


VLOOKUP(

,table_array,col_index_num,range_lookup)

This can now be stated this way...


VLOOKUP(
,where should it be,what you dont know and are
eager to know, what to return)
And this is the INDEX & MATCH syntax...
INDEX(array, MATCH(lookup_value,lookup_array,match_type),column_num)
This can now be stated this way...
INDEX(array, MATCH(
,where should it be,what to return),what
you dont know and are eager to know)
Below you will learn intuitively what takes place behind the scene of any lookup
process

12

How to understand and remember the lookup syntax

Use the practice file "Clients data display - vlookup solution.xls.

13

How To Pull Specific Information From Excel Tables

Use the practice file "Clients data display - i&m solution.xls".


Now you can effectively use VLOOKUP/INDEX & MATCH formulas because you
can make full sense of the lookup arguments.

14

How to set up your data table for perfect matches

The good news about computers is that they do what you tell them to do.
The bad news is that they do what you tell them to do.
Ted Nelson

ow you will learn the key principles to set up your data table so your
VLOOKUP/INDEX & MATCH formulas deliver answers instead of errors.
Let's start...

A table has two main elements, they are


Fixed headers (fields)

This is the row that identifies each column of data. The headers should be
unique so the data is managed without ambiguity, e.g. you can't have two
columns to store the "First name", you neither should store dates in the "City"
column. See the picture below

This row should also be in a different format so you don't include this one in
filtering, sorting, etc. Additionally, Excel detects such row and always asks you

15

How To Pull Specific Information From Excel Tables


if you want to use it as the headers row. You can think headers (columns) as
fixed. This is true for any given table where you work only adding or deleting
rows for the same amount of columns.
Variable rows (records/cells)

This is the data that each column contains; the amount of rows per table
increases or decreases depending on the need of each Excel user.

Here's where most problems occur.


Users modify tables in a database concurrently so they are designed to keep
integrity at all costs; on the other hand, tables in Excel are not designed to
keep such integrity so tables are corrupted easily.
Data in Excel is corrupted effortlessly, for instance when you enter dates in a
column that expects numbers (this should not be done but CAN be done, there
is no restrictions like those of a Database). Another typical problem is that
users modify the same table on their computers and soon both tables differ in
number of rows and also in the quality of records.

On the other hand, an Excel table can only manage three types of data: 1)
Numbers, 2) Dates and 3) Texts.
Knowing these Excel data principles will help you enter data correctly in tables
and avoid non-matching problems and confusions.

A number can be sum, counted, averaged, etc.


How to enter numbers?
To type a number just enter the digits that comprise the number, for example:
10; 213.34; etc.

Be careful to use the correct decimal delimiter, for example: if you type a
comma (12,34) when the decimal delimiter of your computer is set to be a
point (12.34), your number won't be interpreted as a number by Excel (will be
stored as text), and you will get unexpected results in Math operations like
sum, average, etc. and also when you try to match records.
16

How to set up your data table for perfect matches

First, avoid unnecessary mystification, forget the date format, and instead work
with Dates the same way you would do it with numbers.
Why?
this concept is very simple, see below:
The date 01/01/1900 is the number 1 (the minimum Date)
The date 02/01/1900 is the number 2

The date 31/12/9999 is the number 2,958,465 (the maximum Date)


In summary

A date is a sequential number presented as a date format (05/12/2010,


3-Jul-11, etc.).

Excel Dates are Numbers so use Excel Dates conventionally as you would
do it with numbers; you can even perform the same operations:
subtracting, sorting, finding, calculating intervals, etc.

How to enter dates?


The first thing you need to do is setting the date format you will use in your
cells. For example the US format has this sequence MM/DD/YYYY while my
country Ecuador has this sequence DD/ MM /YYYY

You can enter a date as a number (the serial number it represents). For
example the date 06/01/2011 is the number 40695, then you can format it as
a date

Enter dates using the right date format, e.g. just type the month, day and year
using the right sequence (MM/DD/YYYY). You can also use the (/) delimiter

A text is any character or text (a, c, r, hello, Susan, etc.); a text can also be any
alphanumeric character (HH-01, 1A, 2B, etc.)
How to enter texts?
A text does not contain quotes when is entered into an Excel cell

17

How To Pull Specific Information From Excel Tables

Why?
A non-left column is out of sight for the VLOOKUP function. See the picture
below

Why?
Approximate VLOOKUP and INDEX and MATCH need the index column to be
sorted ascending so you get sound results
Why ascending?
That's a good question!
18

How to set up your data table for perfect matches


Here's why
An approximate lookup formula looks the searched value on the index column
from top to bottom and then returns the exact match or the next largest value
that is less than lookup_value.
What does exact match or the next largest value that is less than lookup_value
mean?
Let's explore an example
If you want to find 79.2% in the % column of the table below, then the result
will be 70% because that is
the nearest largest value than 79.2%...

Excel interprets the index column as a perfect line number (properly sorted)
and searches nearest or exact values from left to right. See the picture below

19

How To Pull Specific Information From Excel Tables

Extra spaces at the beginning or end of a cell affect filtering, sorting, searching
and matching. Instead of typing spaces, indent the text within the cell.
Another common mistake is adding units to cells, for example : 100 m2, 10
Ton, etc. See the picture below

Keep the same formatting for the entire column using the same font, colors,
dates/number format, etc.
Excel has a special capability called Extend data range formats and formulas.
When you add new data to the end of a list, Excel extends consistent formatting
and formulas. It extends the format when the three of the five preceding cells
use the same format.

20

How to set up your data table for perfect matches

In the US, the norm is using a dot (.) as a decimals delimiter. In some parts of
the world, the norm is using (,) as a decimals delimiter.
How do you set the decimal delimiter on your computer?
Go to: Start menu>Control Panel>Regional Settings>Regional
options>Customize Regional Options. See the picture below...

21

How To Pull Specific Information From Excel Tables


To enter texts the right way you must follow these simple guidelines

Don't quote texts

Don't add extra spaces

Now you can set up your tables the smart way! And you will get consistent
matches when using VLOOKUP/INDEX & MATCH formulas.

22

How to get rid of #N/A errors once for all with the TIF technology

Watch every detail that affects the accuracy of your work.


Arthur C. Nielsen

ow you will learn the 3-step system (TIF technology) for diagnosing and
preventing #N/A errors when using VLOOKUP/INDEX & MATCH formulas.
First, you need to change the way you interpret Excel errors because...

Let me ask you something easy: find the soccer ball

in this box

It's obvious. There's no soccer ball in it.


Now you say to me: the soccer ball IS NOT in the box.
Now let me ask you another question: is your judgment bad?
In other words, you say the soccer ball is not there but it is?
You are not insane, right?
So your statement the soccer ball is not in the box is not an error, it's the truth.

23

How To Pull Specific Information From Excel Tables


The same happens with Excel, Excel is right on its judgments; it's a computer
application that works with a given set of inputs and provides outputs based on
them (at the bit-by-bit level). So when Excel says #N/A, it's just telling you
something, it is not an error, just a notification of what Excel is seeing.
Now a very important point
Excel interprets Susan and Susan (notice the space at the end) as totally different
pieces of data. So for Excel Susan is a soccer ball and Susan is a golf ball. So
when you search Susan (soccer ball

in Susan (golf ball


), Excel says to you, sorry there is no soccer ball here. It's
that easy. Interestingly, this is the moment when we blame Excel for saying us the
truth. We humans are insane from time to time.
So in summary
#N/A is not an error but a trustworthy message!

Why then you keep struggling with #N/A messages?


You won't be able to judge well if the box that contains the balls is closed, right?
How possibly could you know the box contains a soccer ball, if you cannot see what
contains?
Well, this is exactly what you do when you judge the Excel error messages as bad;
you assume the source table (box) contains the information you are looking for
(soccer balls), but Excel always tells the truth, is a computer and is based on the
input data.
In a sense, you should assume that your source data is a mystery until you really
scrutinize it.
So you should start concluding that something wrong is going on with your source
data, the info you are looking for should not be there.
So we have two kind of not-found messages:

Unconvincing message (your source is not credible)

Genuine message (your source is sacred)

Now you will explore these two scenarios in more detail

To sound great with your music instrument you need to have everything always right
(no exception):
24

How to get rid of #N/A errors once for all with the TIF technology

The song notes

The instrument and

The player

So if you are a great player but have the wrong notes, you will fail; at the same time,
if you are a great player and have the right notes but your instrument is not properly
tuned, you will fail too; finally, if you have the instrument tuned, the right notes but
you are not trained to play the guitar, you will fail also. The same happens with
lookup formulas, if you want to succeed with them you need to have these three
elements always right (no exception):

The data (the song notes)

The index column (the instrument)

The lookup formula (the player)

In summary, a lookup formula is 3-part system so to get a perfect match you need to
have the 3 elements in place: the data table, the index column and the lookup
formula (VLOOKUP/INDEX and MATCH). So you have been introduced to the TIF
approach. The term TIF stands for: Table, Index column and Formula.
Now

25

How To Pull Specific Information From Excel Tables

You cannot get rid of #N/A messages; you can only be sure your values match or
differ. And to be that certain you should follow a 3-step systematic approach (TIF
technology).

Proper Table setting (T)

Proper Index column setting (I)

Proper Formula setting (F)

Here's a simple example...


The report below shows #N/A messages after applying VLOOKUP formulas...

You can first think that the VLOOKUP is wrong so you are prone to check it, or maybe
you are prone to think the source data is the problem or maybe you think you the
index column is wrong, anyway you need to check them all. You will suffer a lot if
you don't have a systematic approach.
Now you will systematically diagnose the problem by following the TIF technology...
You perform several checks on each element: Table, Index column and the formula.

26

How to get rid of #N/A errors once for all with the TIF technology
After checking each element of this example you find that the problem is spaces on
your index column, see below...

27

How To Pull Specific Information From Excel Tables


Here are the spaces in your source data...

Here's a formula you can use to remove spaces from your cells

28

How to get rid of #N/A errors once for all with the TIF technology
In summary...
Replace spaces with this formula: =SUBSTITUTE(A2," ","")
And then replace NBSP (non breaking spaces) with this formula:
=SUBSTITUTE(A2,CHAR(160),"")
You can do both (replacing spaces and NBSP (non breaking spaces) ) using this
formula...
: =SUBSTITUTE(SUBSTITUTE(A2,CHAR(160),"")," ","")
Edit cells in column A to see the formula in action (Use the practice file "removingundesired-characters.xls")
Now you can use VLOOKUP/INDEX & MATCH formulas to work with big tables
because you will not get unexpected #N/A errors, and when you get them you will
know exactly where the problems are.
Thats all for now!

29

You might also like