Excel INDIRECT Function
Excel INDIRECT Function
Excel INDIRECT Function
The INDIRECT function in Excel can be used when you have the
reference of a cell or a range as a text string and you want to get the
values from those references.
In short – you can use the indirect formula to return the reference
specified by the text string.
In this Excel tutorial, I will show you how to use the indirect function in
Excel using some practical examples.
But before I get into the examples, let’s first have a look at its syntax.
Input Arguments
ref_text – A text string that contains the reference to a cell or a named
range. This must be a valid cell reference, or else the function would
return a #REF! error
[a1] – A logical value that specifies what type of reference to use
for ref text. This could either be TRUE (indicating A1 style reference) or
FALSE (indicating R1C1-style reference). If omitted, it is TRUE by
default.
Additional Notes
INDIRECT is a volatile function. This means that it recalculates
whenever the excel workbook is open or whenever a calculation is
triggered in the worksheet. This adds to the processing time and slows
down your workbook. While you can use the indirect formula with small
datasets with little or no impact on the speed, you may see it making
your workbook slower when using it with large datasets
The Reference Text (ref_text) could be:
=INDIRECT("A1")
The above formula takes the cell reference A1 as the input argument
(within double quotes as a text string) and returns the value in this cell,
which is 123.
Now if you’re thinking, why don’t I simply use =A1 instead of using the
INDIRECT function, you have a valid question.
Here is why…
When you use =A1 or =$A$1, it gives you the same result. But when
you insert a row above the first row, you would notice that the cell
references would automatically change to account for the new row.
You can also use the INDIRECT function when you want to lock the cell
references in such a way that it does not change when you insert
rows/columns in the worksheet.
This, in turn, means that the function would refer to cell A1 and return
the value in it.
Note that you don’t need to use double quotes here as the C1 has the
cell reference stored in the text string format only.
Also, in case the text string in cell C1 is not a valid cell reference, the
Indirect function would return the #REF! error.
For example, if cell C1 contains the number 2, and you use the
formula =INDIRECT(“A”&C1) then it would refer to cell A2.
A practical application of this could be when you want to create dynamic
reference to cells based on the value in some other cell.
In case the text string you use in the formula gives a reference that
Excel doesn’t understand, it will return the ref error (#REF!).
You can then use the SUM function to find the total or the
LARGE/SMALL/MIN/MAX function to do other calculations.
Just like the SUM function, you can also use functions such as LARGE,
MAX/MIN, COUNT, etc.
Let’s say you have a worksheet with the name Sheet1, and within the
sheet in the cell A1, you have the value 123. If you go to another sheet
(let’s say Sheet2) and refer to cell A1 in Sheet1, the formula would
be: =Sheet1!A1
But..
If you have a worksheet that contains two or more than two words (with
a space character in between), and you refer to cell A1 in this sheet
from another sheet, the formula would be: =’Data Set’!A1
Suppose you have a sheet named Dataset and cell A1 in it has the value
123.
Now to refer to this cell from another worksheet, use the following
formula:
=INDIRECT("'Data Set'!A1")
As you can see, the reference to the cell needs to contain the worksheet
name as well.
If you have the name of the worksheet in a cell (let’s say A1), then you
can use the following formula:
=INDIRECT("'"&A1&"'!A1")
If you have the name of the worksheet in cell A1 and cell address in cell
A2, then the formula would be:
=INDIRECT("'"&A1&"'!"&A2)
Similarly, you can also modify the formula to refer to a cell in another
workbook.
This could be useful when you trying to create a summary sheet that
pulls the data from multiple different sheets.
For example, suppose you have the marks for 5 students in three
subjects as shown below:
B2:B6: Math
C2:C6: Physics
D2:D6: Chemistry
To name a range of cells, simply select the cells and go to the name
box, enter the name and hit enter.
Now you can refer to these named ranges using the formula:
=INDIRECT("Named Range")
For example, if you want to know the average of the marks in Math, use
the formula:
=AVERAGE(INDIRECT("Math"))
If you have the named range name in a cell (F2 in the example below
has the name Math), you can use this directly in the formula.
The below example shows how to calculate the average using the
named ranges.
For example, suppose you have a list of countries in a row and the name
of cities for each country as shown below:
Now to create a dependent drop-down list, you need to create two
named ranges, A2:A5 with the name US and B2:B5 with the name
India.
Now select cell D2 and create a drop-down list for India and the US. This
would be the first drop-down list where the user gets the option to
select a country.
Select cell E2 (the cell in which you want to get the dependent drop-
down list).
Click OK.
Now, when you enter the US in cell D2, the drop-down in cell E2 will
show the states in the US.
And when you enter India in cell D2, the drop-down in cell E2 will show
the states in India.
So these are some examples to use the INDIRECT function in Excel.
These examples would work on all the versions of Excel (Office 365,
Excel 2019/2016/2013/2013)
10 VLOOKUP Examples
For Beginner & Advanced
Users + FREE EBOOK
Home>>
Blog>>
Excel Functions>>
10 VLOOKUP Examples For Beginner & Advanced Users + FREE EBOOK
This Tutorial Covers:
1. VLOOKUP Function – Introduction
2. Syntax
3. Input Arguments
You know something in Excel if you know how to use the VLOOKUP
function.
If you don’t, you better not list Excel as one of your strong areas in your
resume.
I’ll cover everything there is to know about it, and then show you useful
and practical VLOOKUP examples.
So buckle up.
Remember when the exam score list was out and pasted on the notice
board and everyone used to go crazy finding their names and their score
(at least that’s what used to happen when I was in school).
You go up to the notice board and start looking for your name or enrolment
number (running your finger from top to bottom in the list).
As soon as you spot your name, you move your eyes to the right of the
name/enrolment number to see your scores.
And that is exactly what the Excel VLOOKUP function does for you (feel
free to use this example in your next interview).
VLOOKUP function looks for a specified value in a column (in the above
example, it was your name) and when it finds the specified match, it
returns a value in the same row (the marks you obtained).
Syntax
=VLOOKUP(lookup_value, table_array, col_index_num, [range_lookup])
Input Arguments
lookup_value – this is the look-up value you are trying to find in the left-
most column of a table. It could be a value, a cell reference, or a text string. In
the score sheet example, this would be your name.
table_array – this is the table array in which you are looking for the value.
This could be a reference to a range of cells or a named range. In the score
sheet example, this would be the entire table that contains score for everyone
for every subject
col_index – this is the column index number from which you want to fetch the
matching value. In the score sheet example, if you want the scores for Math
(which is the first column in a table that contains the scores), you’d look in
column 1. If you want the scores for Physics, you’d look in column 2.
[range_lookup] – here you specify whether you want an exact match or an
approximate match. If omitted, it defaults to TRUE – approximate match (see
additional notes below).
In approximate lookup, make sure that the list is sorted in ascending order
(top to bottom), or else the result could be inaccurate.
o If the VLOOKUP function can not find the value, it returns the largest value,
o It returns a #N/A error if the lookup_value is smaller than the smallest value.
below).
Now, hoping that you have a basic understanding of what the VLOOKUP
function can do, let’s peel this onion and see some practical examples of
the VLOOKUP function.
Now let’s get to work and use the VLOOKUP function for what it does
best. From the above data, I need to know how much Brad scored in
Math.
From the above data, I need to know how much Brad scored in Math.
Here is the VLOOKUP formula that will return Brad’s Math score:
=VLOOKUP("Brad",$A$3:$E$10,2,0)
First, it looks for the value Brad in the left-most column. It goes from
top to bottom and finds the value in cell A6.
As soon as it finds the value, it goes to the right in the second column
and fetches the value in it.
You can use the same formula construct to get anyone’s marks in any of
the subjects.
=VLOOKUP("Maria",$A$3:$E$10,4,0)
In the above example, the lookup value (student’s name) is entered in
double quotes. You can also use a cell reference that contains the
lookup value.
For example, if you have a cell with a student’s name, and you are
fetching the score for Math, the result would automatically update when
you change the student’s name (as shown below):
If you enter a lookup value that is not found in the left-most column, it
returns a #N/A error.
To make this two-way lookup formula, you need to make the column
dynamic as well. So when a user changes the subject, the formula
automatically picks the correct column (2 in the case of Math, 3 in the
case of Physics, as so on..).
=VLOOKUP(G4,$A$3:$E$10,MATCH(H3,$A$2:$E$2,0),0)
The above formula uses MATCH(H3,$A$2:$E$2,0) as the column
number. MATCH function takes the subject name as the lookup value (in
H3) and returns its position in A2:E2. Hence, if you use Math, it would
return 2 as Math is found in B2 (which is the second cell in the specified
array range).
The VLOOKUP formula used in this case is the same used in Example 2.
=VLOOKUP(G4,$A$3:$E$10,MATCH(H3,$A$2:$E$2,0),0)
Select the cell in which you want the drop-down list. In this example, in G4, we
want the student names.
In the Data Validation Dialogue box, within the settings tab, select List from
the Allow drop-down.
Click OK.
Now you’ll have the drop-down list in cell G4. Similarly, you can create
one in H3 for the subjects.
=VLOOKUP(G4,CHOOSE(IF(H2="Unit Test",1,IF(H2="Midterm",2,3)),
$A$3:$E$7,$A$11:$E$15,$A$19:$E$23),MATCH(H3,$A$2:$E$2,0),0)
This formula uses the CHOOSE function to make sure the right table is
referred to. Let’s analyze the CHOOSE part of the formula:
CHOOSE(IF(H2=”Unit Test”,1,IF(H2=”Midterm”,2,3)),
$A$3:$E$7,$A$11:$E$15,$A$19:$E$23)
The first argument of the formula is IF(H2=”Unit
Test”,1,IF(H2=”Midterm”,2,3)), which checks the cell H2 and see what
level of exam is being referred to. If it’s Unit Test, it returns $A$3:$E$7,
which has the scores for Unit Test. If it’s Midterm, it
returns $A$11:$E$15, else it returns $A$19:$E$23.
Doing this makes the VLOOKUP table array dynamic and hence makes it
a three-way lookup.
I don’t think you would ever need any calculation involving such a large
number. And that is exactly what we can use get the last number in a
list.
Suppose you have a dataset (in A1:A14) as shown below and you want
to get the last number in the list.
=VLOOKUP(9.99999999999999E+307,$A$1:$A$14,TRUE)
If it finds a value that is higher than the lookup value, it returns the value in
the cell above it.
If the lookup value is greater than all the values in the list, it returns the last
value.
In the same way, you can also use it to return the last text item from
the list. Here is the formula that can do that:
=VLOOKUP("zzz",$A$1:$A$8,1,TRUE)
The same logic follows. Excel looks through all the names, and since zzz
is considered bigger than any name/text starting with alphabets before
zzz, it would return the last item from the list.
Example 6 – Partial Lookup using
Wildcard Characters and VLOOKUP
Excel wildcard characters can be really helpful in many situations.
It’s that magic potion that gives your formulas super powers.
Partial look-up is needed when you have to look for a value in a list and
there isn’t an exact match.
For example, suppose you have a data set as shown below, and you
want to look for the company ABC in a list, but the list has ABC Ltd
instead of ABC.
You can not use ABC as the lookup value as there is no exact match in
column A. Approximate match also leads to erroneous results and it
requires the list to be sorted in an ascending order.
Enter the following formula in cell D2 and drag it to the other cells:
=VLOOKUP("*"&C2&"*",$A$2:$A$8,1,FALSE)
How does this formula work?
In the above formula, instead of using the lookup value as is, it is
flanked on both sides with the wildcard character asterisk (*)
– “*”&C2&”*”
An asterisk is a wildcard character in Excel and can represent any
number of characters.
Using the asterisk on both sides of the lookup value tells Excel that it
needs to look for any text that contains the word in C2. It could have
any number of characters before or after the text in C2.
For example, cell C2 has ABC, so the VLOOKUP function looks through
the names in A2:A8 and searches for ABC. It finds a match in cell A2, as
it contains ABC in ABC Ltd. It doesn’t matter if there are any characters
to the left or right of ABC. Until there is ABC in a text string, it will be
considered a match.
Note: VLOOKUP function always returns the first matching value and
stops looking further. So if you have ABC Ltd., and ABC Corporation in a
list, it will return the first one and ignore the rest.
Example 7 – VLOOKUP Returning an
Error Despite a Match in Lookup Value
It can drive you crazy when you see that there is a matching lookup
value and the VLOOKUP function is returning an error.
For example, in the below case, there is a match (Matt), but the
VLOOKUP function still returns an error.
Now while we can see there is a match, what we can not see with a
naked eye is that there could be leading or trailing spaces. If you have
these additional spaces before, after, or in between the lookup values, it
ISN’T an exact match.
This is often the case when you import data from a database or get it
from someone else. These leading/trailing spaces have a tendency to
sneak in.
=VLOOKUP("Matt",TRIM($A$2:$A$9),1,0)
Since this is an array formula, use Control + Shift + Enter instead of
just Enter.
Another way could be to first treat your lookup array with the TRIM
function to make sure all the additional spaces are gone, and then use
the VLOOKUP function as usual.
Here is an example:
As you can see, there are three cells with the same name (in A2, A4,
and A5) but with a different alphabet case. On the right, we have the
three names (Matt, MATT, and matt) along with their scores in Math.
To get the values in the helper column, use the =ROW() function. It will
simply get the row number in the cell.
Once you have the helper column, here is the formula that will give the
case-sensitive lookup result.
=VLOOKUP(MAX(EXACT(E2,$A$2:$A$9)*(ROW($A$2:$A$9))),$B$2:$C$9,2,0)
Note: Since this is an array formula, use Control + Shift + Enter instead
of just enter.
Example 9 – Using VLOOKUP with
Multiple Criteria
Excel VLOOKUP function, in its basic form, can look for one lookup value
and return the corresponding value from the specified row.
Suppose you have a data with students name, exam type, and the Math
score (as shown below):
Using the VLOOKUP function to get the Math score for each student for
respective exam levels could be a challenge.
For example, if you try using VLOOKUP with Matt as the lookup value,
it’ll always return 91, which is the score for the first occurrence of Matt
in the list. To get the score for Matt for each exam type (Unit Test, Mid
Term and Final), you need to create a unique lookup value.
This can be done using the helper column. The first step is to insert a
helper column to the left of the scores.
Now, to create a unique qualifier for each instance of the name, use the
following formula in C2: =A2&”|”&B2
Copy this formula to all the cells in the helper column. This will create
unique lookup values for each instance of a name (as shown below):
Now, while there were repetitions of the names, there is no repetition
when the name is combined with the level of examination.
This makes it easy as now you can use the helper column values as the
lookup values.
=VLOOKUP($F3&"|"&G$2,$C$2:$D$19,2,0)
Here we have combined the student name and the level of examination
to get the lookup value, and we use this lookup value and checks it in
the helper column to get the matching record.
Note: In the above example, we have used | as the separator while
joining text in the helper column. In some exceptionally rare (but
possible) conditions, you may have two criteria that are different but
ends up giving the same result when combined. Here is an example:
Note that while A2 and A3 are different and B2 and B3 are different, the
combinations end up being the same. But if you use a separator, then
even the combination would be different (D2 and D3).
You can easily remove the error values with any meaning full text such
as “Not Available” or “Not Found”.
For example, in the example below, when you try to find the score of
Brad in the list, it returns an error as Brad’s name is not there in the list.
=IFERROR(VLOOKUP(D2,$A$2:$B$7,2,0),"Not Found")
The IFERROR function checks if the value returned by the first argument
(which is the VLOOKUP function in this case) is an error or not. If it’s not
an error, it returns the value by the VLOOKUP function, else it
returns Not Found.
IFERROR function is available from Excel 2007 onwards. If you are using
versions prior to that, use the following function:
=IF(ISERROR(VLOOKUP(D2,$A$2:$B$7,2,0)),"Not
Found",VLOOKUP(D2,$A$2:$B$7,2,0))
Note: I’ve tried my best to proof read this tutorial, but in case you find
any errors or spelling mistakes, please let me know 🙂