Excel Using V-Lookup and H-Lookup
Excel Using V-Lookup and H-Lookup
V-lookup
and
H-lookup
IT Training
St. George’s, University of
London
Contents
Understanding Tables................................................................................................................. 1
Creating A Table From Data ........................................................................................................................... 2
Inserting Table Columns ................................................................................................................................ 3
Removing Table Columns............................................................................................................................... 4
Working With Table Styles ............................................................................................................................. 5
Inserting Or Deleting Table Records .............................................................................................................. 6
Removing Duplicates ..................................................................................................................................... 7
Filtering Tables ............................................................................................................................................... 8
Renaming A Table .......................................................................................................................................... 9
Deleting A Table ........................................................................................................................................... 10
Understanding Data Lookup Functions ..................................................................................... 11
Using VLOOKUP............................................................................................................................................ 12
Using VLOOKUP For Exact Matches ............................................................................................................. 13
Using HLOOKUP ........................................................................................................................................... 14
Using MATCH ............................................................................................................................................... 15
Using IFERROR.............................................................................................................................................. 16
Absolute Versus Relative Referencing....................................................................................... 17
Relative Formulas......................................................................................................................................... 18
Problems With Relative Formulas................................................................................................................ 19
Creating Absolute References...................................................................................................................... 20
Understanding Data Validation ................................................................................................ 21
Creating Drop-Down Lists ............................................................................................................................ 22
Understanding Labels And Names ............................................................................................................... 23
Lookup Functions ......................................................................................................................................... 24
Lookup Functions ......................................................................................................................................... 25
If you have a St. George’s username and password you can access all the files that goes with this manual.
Files can be found in a folder on the N drive in the IT Training folder named:
Excel using V-lookup and
H-lookup N:\IT Training\ Excel using V-lookup and H-lookup
UNDERSTANDING TABLES
Most spreadsheets provide three functions: calculations much simpler and accessible; the
calculating, graphing, and some limited database charting tools allow users to create graphs; and
functionality. Excel continues on in this tradition. databases can be constructed using tables.
In Excel, formulas and functions make complex
What Is A Table?
A table is made up of columns and rows and can be used to store many different kinds of information.
In applications such as Microsoft Word, a table can be used to create page layouts and lists as well as
perform many other tasks with the main purpose of formatting information. However in Excel the
primary use for a table is to store data. A table that stores data is sometimes known as a database.
Once the data is stored in a table it can then be processed.
In Microsoft Excel a table appears with quite a specific structure. Database tables are organised into
records (rows) and fields (columns) so that the data can easily be sorted and queried. The first row is
normally reserved for the headings – known as field names.
One of the normal database operations you can complete in Excel using a table is sorting the data. For
instance, you can query the data either through the use of filters, or through more advanced
techniques involving criteria (querying by example).
If you are looking for ways to work with data then you may want to use the commands in the Editing
group on the HOME tab; for example, the Sort & Filter command which allows you to sort and filter
data in a worksheet as well as in a table. The DATA tab also contains a Sort & Filter group that contains
a number of commands for sorting data and creating filters.
1
Excel - Lookups
Click in any cell that contains
data
Click on the INSERT tab, then
3
click on Table in the Tables
group to display the Create
Table dialog box
Excel calculates the tables
range by extending in all
directions until empty rows or
columns are reached…
Click on [OK] to create the
table
Click in any cell in the table to 5
remove the selection
highlighting
Click on the TABLE TOOLS:
DESIGN tab, then click on the
More arrow for the Quick
Styles gallery in the Table
Styles group to display a
gallery of options
Point to an option to see it
applied to the table in Live 7
Preview
Click on Table Style Medium 4
to apply this style to the table
To create a table in Excel: By advising Excel that the table has headers,
1. Click anywhere in the list that will become the column headings in the first row become
the table field names and appear with sort and filter
arrows. If the table doesn’t have headings,
2. Click on the INSERT tab, then click on Table
Excel will add its own as Column 1, Column 2
in the Tables group
and so on.
2
Excel - Lookups
2
Try This Yourself:
Continue using the previous
Same File
Click in cell B4
3
Excel - Lookups
2
Try This Yourself:
Continue using the
previous file with this
Same File
Click in cell B4
This is the Colour 3
column of the table…
Click in cell E4
3
Try This Yourself:
Continue using the previous file
Same File
To change styles in a table: The Total Row option on the TABLE TOOLS:
1. Click on the table DESIGN tab inserts a =SUBTOTAL function
using a COUNTA setting to count the
2. Click on the TABLE TOOLS: DESIGN tab
number of records. You can modify this
3. Click on the various Table Style Options to
formula simply by clicking on it as you would
enable or disable them
with any other formula in a worksheet.
5
Excel - Lookups
Click anywhere in row 7 in the
table
2
Click on the HOME tab, then
click on the bottom half of
Insert in the Cells group
Select Insert Table Rows
Above to insert a new row at
row 7
Select the range A10:I10,
then copy and paste it into
the range A7:I7
This will effectively duplicate 3
this record – we’ll deal with
this a little later…
Click in the last cell in the
Telephone column (this will
be cell I94)
Press
Notice that a new row is
inserted into the table…
4
Ensure that the new row is
active, click on the HOME
tab, click on the drop arrow
for Delete in the Cells group,
then select on Delete Table
Rows
REMOVING DUPLICATES
Duplicate entries are an issue when using Excel columns, you don’t have the same checks and
as a database. Most database systems have balances. Fortunately, there is a command
primary keys to identify unique records. Because available that will check for duplication in a table.
tables in Excel are simply normal rows and
Click on [OK]
A message will appear advising
6
Click on [OK]
Notice that the duplicate at row
10 has now gone
7
Excel - Lookups
FILTERING TABLES
Filtering, which allows you to display specific in a filtered list. You can easily specify more
records that match a certain criteria provides advanced ways of filtering and can turn the filter
you with a great opportunity for displaying and results on or off with the click of a button.
hiding records. You can display up to 1,000 items
Click on the filter drop
arrow for the Age
column, as shown
Click on Select All to
remove all of the ticks,
then scroll down and
click on 65
1
This specifies that only
employees aged 65 will
be displayed…
Click on [OK] to display
the employees aged 65
Click on the filter drop
arrow for the Office 3
column, click on Select
All to remove all of the
ticks, click on New York,
then click on [OK]
4
Click on the DATA tab,
then click on Clear in the
Sort & Filter group to
For Your clear all of the filters and
Reference… Handy to Know…
see all of the records
To filter data
againin a table: When you create a filter in a table, Excel
1. Click anywhere in the table area simply hides the rows that don’t match the
2. Use the filter arrows to select the data you filter. That’s why you’ll see some row
wish to view numbers missing.
8
Excel - Lookups
RENAMING A TABLE
In Excel you can have more than one table in a named Table1, Table2 etc. by default; however,
worksheet or workbook. Since a table is actually you can assign more meaningful names if you
part of a range in a worksheet, each table is prefer.
assigned its own unique range name. Tables are
1
Try This Yourself:
Continue using the previous
Same File
5
Click on [OK]
9
Excel - Lookups
DELETING A TABLE
There may come a time when a table is no the table the table itself will remain in place but
longer required. Deleting a table is quite simple, some of its data, headings, or structure may
providing the entire defined range of the table is change depending upon the cell or range you have
selected first. If you attempt to delete parts of deleted.
Click on [Close] 5
To delete a table from a worksheet: The Name Manager dialog box is a useful
1. Select the entire range of the table way of finding out what tables, if any, you
have in a worksheet. If you click on the
2. Press
[Filter] button you can filter the names to
show only table names.
10
Excel - Lookups
1
Data Area
The data area is often on a worksheet by itself, protecting it from accidentally being modified or
deleted. It holds all of the possible values for the data. The values are laid out in a table format and
they are listed in numerical or alphabetical order of the code that the lookup function will search
for.
Calculation Area
The calculation area is usually on a worksheet by itself unless you require the data values to be
2
visible as well as the resulting calculations.
The calculation area uses a formula, such as VLOOKUP, to find the correct data for each situation.
In this example, the VLOOKUP function shown is comparing the value in C5 with the values in the
range Pay_Rates. It then returns the value in the second column of the data table, determined by
11
Excel - Lookups
USING VLOOKUP
The classic lookup function is VLOOKUP – the It then looks across the table to the column you
vertical lookup. This function searches vertically have specified to find the value to return. This is
down a sorted data table looking for a match ideal for looking up numeric values within a range,
with the lookup-value (or the next lowest value). such as tax rates, or commission amounts.
Type =VLOOKUP(F5,Tax_Table,2)
Press
0% appears because the Gross Pay is
less than $500…
Click on C10
12
Excel - Lookups
Click on the Invoice worksheet tab,
then click on C7
We’ll use the exact lookup to find
the description…
Type =VLOOKUP
(B7,Items_List,2,FALSE)
then press
We only want to charge a deposit if
B3 is not blank…
13
Excel - Lookups
USING HLOOKUP
Another commonly used lookup function is the next lowest value). It then looks down the
HLOOKUP – the horizontal lookup. This function table to the row you have specified to find the
searches horizontally across a sorted data table value to return. This can be used to search for text,
looking for a match with the lookup-value (or numbers, or logical values.
Press
The name of the Rate Type will
be returned and displayed…
USING MATCH
The MATCH function looks for an item in a list itself is needed. For example, you can search for a
and returns the position of that item. MATCH is particular category name in an alphabetical list and
used instead of the other lookup functions when return its location in the list, such as 3 for the 3rd
the position of the item rather than the item position or 4 for the 4th position.
Type MATCH(C15,C4:F4)
Press
The formula looks up the text and
returns its position, which is 4 in
this case. This is, in turn, used by
the INDEX function to locate the
correct hire rate for the given rate
type
USING IFERROR
IFERROR is used to trap errors that may occur as return the message #DIV/0! which can be a bit
the result of a calculation and then display alarming for novice users. IFERROR tests a
alternative text or values. For example, if you calculation to see if it works and, if so, performs
divide a number by zero, Excel will normally the calculation. If not, it displays an alternative.
2
Try This Yourself:
Continue using the previous
Same File
Press
4
16
Excel - Lookups
When this formula, or shape, is then copied or filled to adjacent cells it is the shape that is copied and
the cell references within those copied formulas change relative to the shape (which doesn’t change).
For example if you copy =D5*C5 from E5 to E6 the formula in E6 changes to =D6*C6 – but the shape is
still – left one multiply by left two.
This is known as relative referencing – because the cell addresses change relative to the current location.
Absolute Referencing
There will be times however when one or more cell references in a formula are always required to be
located in a specific cell, row, or column. In the example below, sales tax of 10% is located in cell B4 and
must always be referenced from B4. The sales tax for the dining table is calculated using the formula
=B8*B4 while the sales tax for the sofa is calculated using the formula =B9*B4. These are different shapes
and if you were to copy the formula from C8 (=B8*B4) to C9 it would copy the shape and the formula
would be =B9*B5 – which is wrong.
When dealing with cells in formulas that must be referenced from the same location you must fix these
cell references by making them absolute. This is done by placing a $ sign in front of either or both the
row and column co-ordinate of the cell depending on which of these has to remain fixed (e.g. $B$4, $B4,
or B$4). In the example above, both row and column co-ordinates need to be fixed and the formula in
C8 should be written as =B8*$B$4 before it can be copied to adjacent cells.
17
Excel - Lookups
RELATIVE FORMULAS
Most of the formulas that you enter into a be able to change when the formulas are copied to
worksheet, unless you are dealing with quite other locations. This is particularly true of columnar
complex mathematical modelling, will be worksheets where there is a series of columns that
relative formulas where the cell references will all have the same shape and structure.
Press
formula
to complete the
Press
formula
to complete the
18
Excel - Lookups
Type =B11*B5
Notice the shape of the
formula as indicated by the
highlighted cells…
Press
formula
to complete the
5
Handy to Know…
So what has gone wrong with the formulas above? The whole problem hinges on the fact that each of
the formulas in column C uses a different shape from the other formulas. For example, the first
formula in C11 is =B11*B5. The shape of this formula is one left, then six up and one left.
The second formula in C12 has become =B12*B6 because it uses the same shape as the originating
formula in C11. In reality the formula should be =B12*B5. All of the formulas above must reference
the Head Office Surcharge of 12% which is in cell B5 – that is, the cell reference must be absolute.
19
Excel - Lookups
1
Try This Yourself:
Continue using the previous
Same File
Press
editing
to complete the
20
Excel - Lookups
21
Excel - Lookups
Names
If you want to create a tag that refers to a range of cells holding values and text, or that you can use in formulas
on other worksheets, you need to create a Name.
Names are like labels except that the name has to be specified against a particular range, and does not usually
appear on the spreadsheet. Names can be used to refer to cells in other worksheets, in other workbooks, and can
even be used to represent a fixed value rather than a range of cells. For example, if you need to use a constant
value in your calculations, but don’t want the value to appear in the worksheet in case it is accidentally changed,
you can define a name and assign it a value. For example, GST could represent the value 10%.
Need to Know…
There are two important rules to follow when creating Names:
1. You can only use letters of the alphabet, numbers or the underscore character ( _ ) in names.
Spaces and other special characters such as &, * or % are not allowed.
2. Names must not begin with a number. Use a letter or an underscore as the first character of your
name, for example, Yr1996 or _2005.
23
Excel - Lookups
LOOKUP FUNCTIONS
Practice Exercise
Tasks:
Before starting this exercise you MUST have completed all of the
topics in the chapter Lookup Functions…
Use the INDEX functions in cells E6:E8 to reference the winnings table
of the Named Ranges worksheet, based on the following information
on the Awards worksheet:
Quarter: see cell B3
Place: see cells A6:A8 for first, second and third
Copy and modify the formulas so that they refer to the correct cells
for each quarter, completing the worksheet as shown in the sample
on the next page
24
Excel - Lookups
LOOKUP FUNCTIONS
Practice Exercise
25