AE Unit1
AE Unit1
AE Unit1
***What is Excel?
The first version was released in 1985 and has gone through several changes
over the years. However, the main functionality mostly remains the same.
Analysis
Data entry
Data management
Accounting
Budgeting
Data analysis
Visuals and graphs
Programming
Financial modeling
And much, much more!
Have a look at the picture below. The Ribbon is marked with a red rectangle
and the Sheet is marked with a yellow rectangle:
*The Ribbon is made up by the App launcher, Tabs, Groups and Commands. In
this section we will explain the different parts of the Ribbon.
**App launcher
The App launcher icon has nine dots and is called the Office 365 navigation bar.
It allows you to access the different parts of the Office 365 suite, such as Word,
PowerPoint and Outlook. App launcher can be used to switch seamlessly
between the Office 365 applications.
**Tabs
The tab is a menu with sub divisions sorted into groups. The tabs allow users to
quickly navigate between options of menus which display different groups of
functionality.
**Groups
The groups are sets of related commands. The groups are separated by the
thin vertical line break.
**Commands
Now, let's have a look at the Sheet. Soon you will be able to understand the
relationship between the Ribbon and the Sheet, and you can make things
happen.
**The Sheet explained
The Sheet is a set of rows and columns. It forms the same pattern as we have
in math exercise books, the rectangle boxes formed by the pattern are called
cells.
***Relative Reference
**Introduction
There are two types of cell references: relative and absolute. Relative and
absolute references behave differently when copied and filled to other cells.
Relative references change when a formula is copied to another cell. Absolute
references, on the other hand, remain constant no matter where they are
copied.
**Relative references
By default, all cell references are relative references. When copied across
multiple cells, they change based on the relative position of rows and columns.
For example, if you copy the formula =A1+B1 from row 1 to row 2, the formula
will become =A2+B2. Relative references are especially convenient whenever
you need to repeat the same calculation across multiple rows or columns.
In the following example, we want to create a formula that will multiply each
item's price by the quantity. Instead of creating a new formula for each row,
we can create a single formula in cell D4 and then copy it to the other rows.
We'll use relative references so the formula calculates the total for each item
correctly.
1. Select the cell that will contain the formula. In our example, we'll
select cell D4.
5. Click and drag the fill handle over the cells you want to fill. In our
example, we'll select cells D5:D13.
6. Release the mouse. The formula will be copied to the selected cells
with relative references, displaying the result in each cell.
You can double-click the filled cells to check their formulas for accuracy. The
relative cell references should be different for each cell, depending on their
rows.
***Absolute references
There may be a time when you don't want a cell reference to change when
copied to other cells. Unlike relative references, absolute references do not
change when copied or filled. You can use an absolute reference to keep a row
and/or column constant.
You will generally use the $A$2 format when creating formulas that contain
absolute references. The other two formats are used much less frequently.
When writing a formula, you can press the F4 key on your keyboard to switch
between relative and absolute cell references.This is an easy way to quickly
insert an absolute reference.
To create and copy a formula using absolute references:
In the example below, we'll use cell E2 (which contains the tax rate of 7.5%) to
calculate the sales tax for each item in column D. To make sure the reference
to the tax rate stays constant—even when the formula is copied and filled to
other cells—we'll need to make cell $E$2 an absolute reference.
1. Select the cell that will contain the formula. In our example, we'll
select cell D4.
5. Click and drag the fill handle over the cells you want to fill
(cells D5:D13 in our example).
6. Release the mouse. The formula will be copied to the selected
cells with an absolute reference, and the values will be calculated
in each cell.
You can double-click the filled cells to check their formulas for accuracy. The
absolute reference should be the same for each cell, while the other
references are relative to the cell's row.
Be sure to include the dollar sign ($) whenever you're making an absolute
reference across multiple cells. The dollar signs were omitted in the example
below. This caused Excel to interpret it as a relative reference, producing an
incorrect result when copied to other cells.
Excel allows you to refer to any cell on any worksheet, which can be especially
helpful if you want to reference a specific value from one worksheet to
another. To do this, you'll simply need to begin the cell reference with
the worksheet name followed by an exclamation point (!). For example, if you
wanted to reference cell A1 on Sheet1, its cell reference would be Sheet1!A1.
Note that if a worksheet name contains a space, you'll need to include single
quotation marks (' ') around the name. For example, if you wanted to
reference cell A1 on a worksheet named July Budget, its cell reference would
be 'July Budget'!A1.
To reference cells across worksheets:
In our example below, we'll refer to a cell with a calculated value between two
worksheets. This will allow us to use the exact same value on two different
worksheets without rewriting the formula or copying data.
1. Locate the cell you want to reference, and note its worksheet. In
our example, we want to reference cell E14 on the Menu
Order worksheet.
If you rename your worksheet at a later point, the cell reference will be
updated automatically to reflect the new worksheet name.
If you enter a worksheet name incorrectly, the #REF! error will appear in the
cell. In our example below, we've mistyped the name of the worksheet.
To edit, ignore, or investigate the error, click the Error button beside the cell
and choose an option from the menu.
When you create a spreadsheet, you may enter data or formulas that you do
not want other users to change. Protecting a cell or worksheet can be essential
to maintaining the integrity of data and formulas in a spreadsheet.
In Microsoft Excel, you can protect one or more cells, or protect an entire
worksheet, preventing other users from changing the data in the cells or
worksheet. After locking and protecting cells or worksheets, to edit them
again, you need to unprotect them.
1. Select all cells in the worksheet by clicking the Select All button,
found above the row numbers and to the left of the column
headers.
2. Press Ctrl+1 to open the Format Cells window. You can also
use Ctrl+Shift+F combination to open the Format Cells window.
4. Uncheck the box for the Locked option, then click OK.
5. In the worksheet, select the cell you want to lock and protect.
11.In the Allow all users of this worksheet to section, make sure
only the box for the Select unlocked cells option is checked,
then click OK.
12.Enter the password again in the Confirm Password window and
click OK.
3. In the Unprotect Sheet sheet window that pops up, enter the
password to unlock the worksheet, then click OK.
**Basic functions
To use these functions correctly, you need to understand the different parts of
a function and how to create arguments in functions to calculate values and
cell references.
The order in which you insert a function is important. Each function has a
specific order—called syntax—which must be followed in order for the
function to work correctly. The basic syntax to create a formula with a function
is to insert an equals sign (=), function name (SUM, for example, is the
function name for addition), and argument. Arguments contain the
information you want the formula to calculate, such as a range of cell
references.
Working with arguments
Excel will not always tell you if your function contains an error, so it's up to
you to check all of your functions.
The AutoSum command allows you to automatically return the results for a
range of cells for common functions like SUM and AVERAGE.
1. Select the cell where the answer will appear (E24, for example).
2. Click the Home tab.
3. In the Editing group, click the AutoSum drop-down arrow and
select the function you want (Average, for example).
The AutoSum command can also be accessed from the Formulas tab.
You can also use the Alt+= keyboard shortcut instead of the AutoSum
command. To use this shortcut, hold down the Alt key and then press
the equals sign.
There are hundreds of functions in Excel, but only some will be useful for the
type of data you're working with. There is no need to learn every single
function, but you may want to explore some of the different types to get ideas
about which ones might be helpful to you as you create new spreadsheets.
6. Insert the cursor in the next field, then enter or select the cell(s)
you want (H6, for example).
7. Click OK, and the result will appear. Our results show that it took
five days to receive the order.
The Insert Function command is convenient because it allows you to search for
a function by typing a description of what you're looking for or by selecting a
category to peruse. The Insert Function command can also be used to easily
enter or select more than one argument for a function.
In this example, we want to find a function that will count the total number of
supplies listed in the Office Supply Order Log. The basic COUNT function only
counts cells with numbers; we want to count the cells in the Office Supply
column, which uses text. Therefore, we'll need to find a formula that counts
cells with text.
1. Select the cell where the answer will appear (A27, for example).
2. Click the Formulas tab, then select the Insert Function command.
3. The Insert Function dialog box will appear.
4. Type a description of the function you are searching for, then
click Go (Count cells with text, for example). You can also search
by selecting a category.
5. Review the results to find the function you want (COUNTA, for
example). Click OK.
6. The Function Arguments dialog box will appear. Insert the cursor
in the first field, then enter or select the cell(s) you want (A6:A14,
for example).
7. Insert the cursor in the next field, then enter or select the cell(s)
you want (A19:A23, for example). You can continue to add
additional arguments if needed.
8. Click OK, and the result will appear. Our results show that 14 Total
Supplies were ordered from our log.
=IF(logical_test,[value_if_true],[value_if_false])
As an example, you can include this formula in cell D2 to list the player with
the highest score:
=IF(B2>C2,B1,C1)
You can also use the AND, OR, and NOT functions to produce TRUE and FALSE
results.
=AND(B2>1,C2>1)
10
=OR(B2>1,C2>1)
=NOT(C2>1)
You can also use <> as an operator in your formula in place of “not equal to”
like so:
=OR(B2<>0,C3<1)
**Why use Conditional Formulas?
At some point in time, when you are faced with a lot of data in your
spreadsheets, you may want to find a way to highlight or “filter” out some of
your data based on specific criteria. For example, if you wanted to see if the
value of a cell in column A is equal to the value of a cell in column B
(duplicates), you can use a conditional formula in column C to give you a TRUE
or FALSE result.
=IF(A1=B1,TRUE,FALSE)
This can be helpful if you are using this formula across a large range of cells
and you want to be able to catch any anomalies. In another example, if you
were trying to determine which cells have values of a certain range, you can
also use the IF function to create a conditional formula like:
=IF(A1>3,TRUE,FALSE)
If your objective is to count how many cells fit a specific criteria (e.g. values
greater than 50), you would probably be better off using the COUNTIF function.
However, the benefit to using basic conditional formulas with the IF function is
that you can use this formula for conditional formatting so you can highlight
cells that match a criteria of your choosing.
[e.g. if you’re trying to use a formula that is dependent upon conditions, you
can “nest” your functions (where multiple functions are used within each
other)In this example, if you were to calculate the difference of one player’s
victories over the other (without ending up with negatives) and to also denote
if there is a tie, you could use a formula like:
=IF(B7>C7,B7-C7,IF(C7>B7,C7-B7,”Tie”))
This formula is actually two IF formulas in one…first, you have the first IF
formula IF(B7>C7,B7-C7,…). However, with the value_if_false part of the
equation, you include yet another IF formula: IF(C7>B7,C7-B7,”Tie”). If both
the first IF formula is false (meaning that B7 is NOT greater than C7) AND the
second IF formula is also false (C7 is NOT greater than B7), then the final false
value carries over from the second (or in this case, inner-most) IF formula,
which is “Tie.”
For this example, let’s say you wanted to determine if Player 2 had a good
game day by not only determining if Player 2 was a winner of the game, but
that they also scored more than 3 points. You can create an IF formula with a
nested AND formula so that you can narrow down your results to just the
games where Player 2 met BOTH criteria like so:
In this formula, if Player 2 (cell C1) is the victor (cell D2) of the game, AND
Player 2’s score (cell C2) is greater than 3, then a result of “Good Game” is
produced, otherwise it will result in “Needs Improvement.” This means that if
Player 1 wins, if there is a tie, or if Player 2 wins but doesn’t score more than 3
points, it will result in a “Needs Improvement” result. If you wanted to adjust
the formula so that if Player 2 scores 3 points and you want a “Good Game”
result instead of “Needs Improvement,” then you would adjust the > symbol to
a greater than or equal to symbol >= in the formula.
**Conditional formatting
With Excel 2007, 2010 & 2013’s conditional formatting, you have several
options available that you can use to highlight the cells that you apply the
formatting to based on the selected cells’ value. But what if you wanted to
format cells based on criteria that is out of the scope of the default options?
You do it with a formula, of course!
In the Conditional Formatting menu, you can select the “Use a formula to
determine which cells to format” rule type, which will provide you with a box
for entering your formula. If, for instance, you wanted to highlight the cell
listing the Game number (i.e. cells A2:A5) based on the values of the cells in an
adjacent column (column D in this case which lists who the victor was), you
could use a formula such as:
=IF($D2=”Player 2″,TRUE,FALSE)
=AND(MONTH(C2)=MONTH(TODAY()),D2=”Sales”)
Keep in mind that by default, if you click on the cell you are using in the
formula, Excel will create an absolute reference (using $ in front of the column
letter and row number). If you want your formula to adjust along with the cells
that it applies to, you will need to remove these absolute references by simply
removing the $ accordingly). Once you’ve got your formula nice and spiffed up,
click on the Format button to designate the formatting you wish to apply (I’ve
chosen the cell fill color of blue), then hit OK.
Since I only applied this formatting to cell A2, I want to adjust the range of this
conditional format, so I will go to the Conditional Formatting menu, and under
Manage Rules, I can “stretch out” the range of this condition. Also, if I wanted
to apply another conditional format, say to highlight the games that Player 1
had won but in a different color, you can create a new rule with a new format
by following the same steps you did before, but adjusting the formula
to =IF($D2=”Player 1″,TRUE,FALSE) and changing the cell fill color (I chose
red).
You can repeat the same steps to highlight the cells that have a tie (I used a
purple cell fill color) with this formula in a new rule:
=IF($D2=”Tie”,TRUE,FALSE)
Make sure to adjust the ranges for the conditional formatting rules and you’ve
got a color coded list that adjusts when the scores change.
Microsoft Excel provides 4 logical functions to work with the logical values. The
functions are AND, OR, XOR and NOT. You use these functions when you want
to carry out more than one comparison in your formula or test multiple
conditions instead of just one. As well as logical operators, Excel logical
functions return either TRUE or FALSE when their arguments are evaluated.
The following table provides a short summary of what each logical function
does to help you choose the right formula for a specific task.
Formula
Function Description Formula Description
Example
the argument is
FALSE, then TRUE is
otherwise.
returned and vice
versa.
The AND function is the most popular member of the logic functions family. It
comes in handy when you have to test several conditions and make sure that
all of them are met. Technically, the AND function tests the conditions you
specify and returns TRUE if all of the conditions evaluate to TRUE, FALSE
otherwise.
AND(logical1, [logical2], …)
Where logical is the condition you want to test that can evaluate to either
TRUE or FALSE. The first condition (logical1) is required, subsequent conditions
are optional.
And now, let's look at some formula examples that demonstrate how to use
the AND functions in Excel formulas.
Formula Description
By itself, the Excel AND function is not very exciting and has narrow usefulness.
But in combination with other Excel functions, AND can significantly extend the
capabilities of your worksheets.
One of the most common uses of the Excel AND function is found in the
logical_test argument of the IF function to test several conditions instead of
just one. For example, you can nest any of the AND functions above inside the
IF function and get a result similar to this:
For more IF / AND formula examples, please check out his tutorial: Excel IF
function with multiple AND conditions.
If you need to create a between formula in Excel that picks all values between
the given two values, a common approach is to use the IF function with AND in
the logical test.
For example, you have 3 values in columns A, B and C and you want to know if
a value in column A falls between B and C values. To make such a formula, all it
takes is the IF function with nested AND and a couple of comparison operators:
=IF(AND(A2>=B2,A2<=C2),"Yes", "No")
As demonstrated in the screenshot above, the formula works perfectly for all
data types - numbers, dates and text values. When comparing text values, the
formula checks them character-by-character in the alphabetic order. For
example, it states that Apples in not between Apricot and Bananas because the
second "p" in Apples comes before "r" in Apricot.
As you see, the IF /AND formula is simple, fast and almost universal. I say
"almost" because it does not cover one scenario. The above formula implies
that a value in column B is smaller than in column C, i.e. column B always
contains the lower bound value and C - the upper bound value. This is the
reason why the formula returns "No" for row 6, where A6 has 12, B6 - 15 and
C6 - 3 as well as for row 8 where A8 is 24-Nov, B8 is 26-Dec and C8 is 21-Oct.
But what if you want your between formula to work correctly regardless of
where the lower-bound and upper-bound values reside? In this case, use the
Excel MEDIAN function that returns the median of the given numbers (i.e. the
number in the middle of a set of numbers).
So, if you replace AND in the logical test of the IF function with MEDIAN, the
formula will go like:
=IF(A2=MEDIAN(A2:C2),"Yes","No")
As you see, the MEDIAN function works perfectly for numbers and dates, but
returns the #NUM! error for text values. Alas, no one is perfect : )
If you want a perfect Between formula that works for text values as well as for
numbers and dates, then you will have to construct a more complex logical
text using the AND / OR functions, like this:
As well as AND, the Excel OR function is a basic logical function that is used to
compare two values or statements. The difference is that the OR function
returns TRUE if at least one if the arguments evaluates to TRUE, and returns
FALSE if all arguments are FALSE. The OR function is available in all versions of
Excel 2016 - 2000.
OR(logical1, [logical2], …)
Where logical is something you want to test that can be either TRUE or FALSE.
The first logical is required, additional conditions (up to 255 in modern Excel
versions) are optional.
And now, let's write down a few formulas for you to get a feel how the OR
function in Excel works.
Formula Description
Naturally, nothing prevents you from using both functions, AND & OR, in a
single formula if your business logic requires this. There can be infinite
variations of such formulas that boil down to the following basic patterns:
=OR(AND(Cond1,Cond2), AND(Cond3,Cond4))
=OR($B2="", $C2="")
The rule with the above OR formula highlights rows that contain an empty cell
either in column B or C, or in both.
XOR(logical1, [logical2],…)
The first logical statement (Logical 1) is required, additional logical values are
optional. You can test up to 254 conditions in one formula, and these can be
logical values, arrays, or references that evaluate to either TRUE or FALSE.
In the simplest version, an XOR formula contains just 2 logical statements and
returns:
When more logical statements are added, the XOR function in Excel results in:
If you are not sure how the Excel XOR function can be applied to a real-life
scenario, consider the following example. Suppose you have a table of
contestants and their results for the first 2 games. You want to know which of
the payers shall play the 3rd game based on the following conditions:
Contestants who won Game 1 and Game 2 advance to the next round
automatically and don't have to play Game 3.
Contestants who lost both first games are knocked out and don't play Game 3
either.
Contestants who won either Game 1 or Game 2 shall play Game 3 to
determine who goes into the next round and who doesn't.
=XOR(B2="Won", C2="Won")
And if you nest this XOR function into the logical test of the IF formula, you will
get even more sensible results:
=IF(XOR(B2="Won", C2="Won"), "Yes", "No")
The NOT function is one of the simplest Excel functions in terms of syntax:
NOT(logical)
You use the NOT function in Excel to reverse a value of its argument. In other
words, if logical evaluates to FALSE, the NOT function returns TRUE and vice
versa. For example, both of the below formulas return FALSE:
=NOT(TRUE)
=NOT(2*2=4)
Why would one want to get such ridiculous results? In some cases, you might
be more interested to know when a certain condition isn't met than when it is.
For example, when reviewing a list of attire, you may want to exclude some
color that does not suit you. I'm not particularly fond of black, so I go ahead
with this formula:
=NOT(C2="black")
As usual, in Microsoft Excel there is more than one way to do something, and
you can achieve the same result by using the Not equal to operator:
=C2<>"black".
If you want to test several conditions in a single formula, you can use NOT in
conjunctions with the AND or OR function. For example, if you wanted to
exclude black and white colors, the formula would go like:
=NOT(OR(C2="black", C2="white"))
And if you'd rather not have a black coat, while a black jacket or a back fur coat
may be considered, you should use NOT in combination with the Excel AND
function:
=NOT(AND(C2="black", B2="coat"))
Another common use of the NOT function in Excel is to reverse the behavior of
some other function. For instance, you can combine NOT and ISBLANK
functions to create the ISNOTBLANK formula that Microsoft Excel lacks.
As you know, the formula =ISBLANK(A2) returns TRUE of if the cell A2 is blank.
The NOT function can reverse this result to FALSE: =NOT(ISBLANK(A2))
And then, you can take a step further and create a nested IF statement with
the NOT / ISBLANK functions for a real-life task:
Translated into plain English, the formula tells Excel to do the following. If the
cell C2 is not empty, multiply the number in C2 by 0.15, which gives the 15%
bonus to each salesman who has made any extra sales. If C2 is blank, the text
"No bonus :(" appears.
Lookup and reference functions (reference)
Function Description
ADDRESS function Returns a reference as text to a single cell in a worksheet
AREAS function Returns the number of areas in a reference
CHOOSE function Chooses a value from a list of values
CHOOSECOLS function Returns the specified columns from an array
dimensions
FILTER function Filters a range of data based on criteria you define
HLOOKUP function Looks in the top row of an array and returns the value
a larger array
HYPERLINK function Creates a shortcut or jump that opens a document stored
Function Description
or array
INDIRECT function Returns a reference indicated by a text value
LOOKUP function Looks up values in a vector or array
MATCH function Looks up values in a reference or array
OFFSET function Returns a reference offset from a given reference
ROW function Returns the row number of a reference
ROWS function Returns the number of rows in a reference
RTD function Retrieves real-time data from a program that supports
COM automation
SORT function Sorts the contents of a range or array
SORTBY function Sorts the contents of a range or array based on the values
a larger array
VLOOKUP function Looks in the first column of an array and moves across
(approximate) match.
XMATCH function Returns the relative position of an item in an array or
range of cells.
Here is the syntax for these three very powerful functions in plain English:
If you are using Excel 365, you can use the new & improved XLOOKUP function. It
offers a shorter & more versatile syntax for performing lookups.
For ex: the same lookup as above will be done with XLOOKUP like below:
=XLOOKUP(“Jimmy”, A2:A14, C2:C14) will lookup “Jimmy” in column A and
return sales amount from Column C.
INDEX function is your way of telling excel to fetch a value from large range of
values. Since MATCH() function can tell us where the data is found, you can then
use INDEX() function to extract corresponding data from another column. In this
case, we can use MATCH() to find out which row has net sales 1,799 and INDEX()
to return the name of the person. Like this:
Find the position of 1,799 in sales: =MATCH(1799, $C$2:$C$14, 0)
The answer will be 8.
To find the 8th person in names list, we can use INDEX() function like this:
=INDEX($A$2:$A$14, 8)
The answer will be Jagjit.
Related: Learn more about INDEX Formula.
Finally
Remember, both VLOOKUP and MATCH throw a fail error of #N/A if the value
you are looking for is not there. If you want to stop seeing the error, use
IFERROR function.
Since you are here, I assume that you want to look up some values in multiple
tables. If any of the tables contains the given lookup value, you want to
retrieve them using Excel VLOOKUP function. Right? Here's how you do it.
Generic Formula for the nested VLOOKUP function
=IFERROR(VLOOKUP(lookup_value,table1,col,0),IFERROR(VLOOKUP(lookup_val
ue,table2,col,0),VLOOKUP(lookup_value,table3,col,0)))
lookup_value: This the value you are looking for in your record.
Table1, Tabl2, Table3,...: These are the tables in which you know that the
value exists.
col: The column number in the table from which you want to fetch the value.
0: This is for an exact match. If you want to do an approximate match use 1.
Let's have an example make things clear.
Using nested VLOOKUPs to search multiple tables
Let's create a scenario first. Assume that we run three Yoga classes. At the end
of the day, you find a wrist band that has the name John on it. Now you know
that John belongs to one of three classes. To lookup john in all three classes,
we will need to put nested or chained VLOOKUP function inside the IFERROR
functions.
Here, we want to lookup john using VLOOKUP in all three tables and fetch his
phone number.
Using the above generic formula, we put this formula in cell E12.
=IFERROR(VLOOKUP(D12,B2:C7,2,0),IFERROR(VLOOKUP(D12,F2:G7,2,0),VLOOK
UP(D12,J2:K7,2,0)))
Here, D12 is our lookup value.
B2:C7, F2:G7, and J2:K7 are the tables that we want to search in.
2 is the column number of tables from which we want to retrieve the number.
(Here column number is the same for every table, but it can be different in
different data sets).
When you hit the enter button, it retrieves john's number.
For starters, let's investigate a simplest case - using VLOOKUP to copy data
from another worksheet. It's very similar to a regular VLOOKUP formula that
searches on the same worksheet. The difference is that you include the sheet
name in the table_array argument to tell your formula in which worksheet the
lookup range is located.
As an example, let's pull the sales figures from Jan report to Summary sheet.
For this, we define the following arguments:
Lookup_values are in column A on the Summary sheet, and we refer to the first
data cell, which is A2.
Table_array is the range A2:B6 on the Jan sheet. To refer to it, prefix the range
reference with the sheet name followed by the exclamation point: Jan!
$A$2:$B$6.
Please pay attention that we lock the range with absolute cell references to
prevent it from changing when copying the formula to other cells.
Col_index_num is 2 because we want to copy a value from column B, which is
the 2nd column in the table array.
Drag the formula down the column and you will get this result:
In a similar manner, you can Vlookup data from the Feb and Mar sheets:
For example, to search for A2 value in the range A2:B6 on Jan sheet in
the Sales_reports.xlsx workbook, use this formula:
For full details, please see VLOOKUP from another workbook in Excel.
When you need to look up between more than two sheets, the easiest solution
is to use VLOOKUP in combination with IFERROR. The idea is to nest several
IFERROR functions to check multiple worksheets one by one: if the first
VLOOKUP does not find a match on the first sheet, search in the next sheet,
and so on.
To see how this approach works on real-life data, let's consider the following
example. Below is the Summary table that we want to populate with the item
names and amounts by looking up the order number in West and East sheets:
First, we are going to pull the items. For this, we instruct the VLOOKUP formula
to search for the order number in A2 on the East sheet and return the value
from column B (2nd column in table_array A2:C6). If an exact match is not
found, then search in the West sheet. If both Vlookups fail, return "Not found".
Tip. If needed, you can specify different table arrays for different VLOOKUP
functions. In this example, both lookup sheets have the same number of rows
(A2:C6), but your worksheets may be different in size.
As the result, you get a kind of dynamic formula that extracts matching values
from different columns, depending on which column the formula is copied to:
When copied to column C (i.e. you've dragged the formula from B2 to C2), B$1
changes to C$1 because the column reference is relative. Consequently,
COLUMNS($A$1:C$1) evaluates to 3 forcing VLOOKUP to return a value from
the 3rd column.
This formula works great for 2 - 3 lookup sheets. If you have more, repetitive
IFERRORs become too cumbersome. The next example demonstrates a bit
more complicated but a lot more elegant approach.
Vlookup multiple sheets with INDIRECT
Where:
For the formula to work correctly, please bear in mind the following caveats:
3. Enter the formula in the topmost cell (B2 in this example) and press Ctrl +
Shift + Enter to complete it.
4. Double click or drag the fill handle to copy the formula down the column.
As the result, we've got the formula to look up the order number in 4 sheets
and retrieve the corresponding item. If a specific order number is not found, a
#N/A error is displayed like in row 14:
If you'd like to replace the standard #N/A error notation with your own text,
wrap the formula into the IFNA function:
This generic formula (or its any variation) can also be used to Vlookup multiple
sheets in a different workbook. For this, concatenate the workbook name
inside INDIRECT like shown in the below formula:
If you want to pull data from several columns, a multi-cell array formula can
do that in one go. To create such a formula, supply an array constant for
the col_index_num argument.
In this example, we wish to return the item names (column B) and amounts
(column C), which are the 2nd and 3rd columns in the table array, respectively.
So, the required array is {2,3}.
To correctly enter the formula in multiple cells, this is what you need to do:
In the first row, select all the cells to be populated (B2:C2 in our example).
Type the formula and press Ctrl + Shift + Enter. This enters the same formula in
the selected cells, which will return a different value in each column.
Drag down the formula to the remaining rows.
To better understand the logic, let's break down this basic formula to the
individual functions:
Working from the inside out, here's what the formula does:
COUNTIF and INDIRECT
In a nutshell, INDIRECT builds the references for all lookup sheets, and
COUNTIF counts the occurrences of the lookup value (A2) in each sheet:
In more detail:
First, you concatenate the range name (Lookup_sheets) and the range
reference ($A$2:$A$6), adding apostrophes and the exclamation point in the
right places to make an external reference, and feed the resulting text string to
the INDIRECT function to dynamically refer to the lookup sheets:
COUNTIF checks each cell in the range A2:A6 on each lookup sheet against the
value in A2 on the main sheet and returns the count of matches for each sheet.
In our dataset, the order number in A2 (101) is found in the West sheet, which
is 4th in the named range, so COUNTIF returns this array:
{0;0;0;1}
--({0; 0; 0; 1}>0)
This yields an array of TRUE (greater than 0) and FALSE (equal to 0) values,
which you coerce to 1's and 0's by using a double unary (--), and get the
following array as the result:
{0; 0; 0; 1}
To lookup multiple matches with the VLOOKUP Function you need to create a
helper column within the table of data. The helper column uses the COUNTIF
Function to create a unique ID for each instance. The helper column must be
the leftmost column within the data set. If it’s not practical to adjust the data
set, you should look into the other method in the next section.
Step 1:
Specifically, the range referenced: B6:B$11 . Notice the $ Sign. The $ Sign
“locks” the cell reference: B$11. So as you copy the formula down, B$11 stays
locked. B6, however, is not locked, so as you copy the formula down B6 turns
into B7, etc. This technique, creates a unique number for each instance found.
The reason we leave B6 unlocked is so that as an instance is accounted for, it’s
removed from the total count, creating the unique number.
Also notice the &. & merges the Product Name with it’s instance number to
create one field that we will use in our lookup.
Step 2:
We’ve moved the new helper column (project_adj) to the left of the data set in
B14:C19. Now we can perform the VLOOKUP on multiple results. Instead of
searching for socks, search for socks1 and socks2. Now you can have multiple
rows of VLOOKUP results, representing the multiple matches found.
The downside to this method is you must edit the original data set (or
copy/paste the data set elsewhere) to perform the multiple results VLOOKUP.
Alternatively, you can use INDEX / MATCH Method:
Most Excel users are aware of the power of the VLOOKUP Function, but many
are not aware of the power of the INDEX Function and the Match Function
used in combination. The INDEX / MATCH combination can be used to emulate
a VLOOKUP, with the advantage of more flexibility.
Note: The image directly below contains the formulas. The bottom image
contains the formula results.