Comparing and linking tables of data using VLOOKUP

14
[Type here] Comparing and linking tables of data using VLOOKUP This document looks at how you can minimise duplication in your Excel data by sharing data between worksheets. Instead of copying and pasting data into a new worksheet for analysis, you can use cell referencing and functions to pull data from other Excel sources Videos of using VLOOKUP are available to view on our website Last updated By Faye Brockwell 20 th November 2017 This document is held online on our website: https://staff.brighton.ac.uk/is/training

Transcript of Comparing and linking tables of data using VLOOKUP

Page 1: Comparing and linking tables of data using VLOOKUP

[Type here]

Comparing and linking

tables of data using

VLOOKUP

This document looks at how you can minimise duplication in

your Excel data by sharing data between worksheets.

Instead of copying and pasting data into a new worksheet for

analysis, you can use cell referencing and functions to pull

data from other Excel sources

Videos of using

VLOOKUP are

available to view on

our website

Last updated

By Faye Brockwell

20th November 2017

This document is held online on our website:

https://staff.brighton.ac.uk/is/training

Page 2: Comparing and linking tables of data using VLOOKUP

University of Brighton Information Services

Page | 2 Last Updated Faye Brockwell

Contents

VLOOKUP videos on our website .................................................................... 2

VLOOKUP Functions ....................................................................................... 3

Note on holding data in Excel ........................................................................... 3

Steps for using VLOOKUP ............................................................................... 4

Prepare your data table .................................................................................... 4

Sort the master data table ......................................................................... 4

Name the master data table ...................................................................... 4

Build the VLOOKUP function ........................................................................... 5

To build the VLOOKUP function................................................................ 6

Copy the VLOOKUP to the rest of the worksheet ............................................. 7

Excercises ....................................................................................................... 8

Solutions .........................................................................................................12

VLOOKUP videos on our website

We have put together a Lynda.com playlist with videos showing how to build

VLOOKUPS. For links to the playlist, visit

https://staff.brighton.ac.uk/is/training/Pages/Excel/linking.aspx

You will also find examples of using VLOOKUP to populate CAMS assessment

sheets on the following pages of our website:

https://staff.brighton.ac.uk/is/training/Pages/Excel/linking.aspx

https://staff.brighton.ac.uk/is/training/Pages/Excel/CAMS.aspx

Page 3: Comparing and linking tables of data using VLOOKUP

Comparing and linking tables of data using VLOOKUP

https://staff.brighton.ac.uk/is/training/Pages/Excel/linking.aspx Page | 3

VLOOKUP Functions

VLOOKUP functions are used to pull data into a cell from a master data table. Some

examples of where this can be used:

On a sheet recording interactions with a student, automatically populate a student’s

name and course details when the student number is typed in.

On a sheet listing student marks, automatically populate the grade and check digit

when the mark is typed in.

On a list of employees, automatically populate the tax rate based on salary.

This is especially useful where several spreadsheets use the same data. You can have

one sheet holding that data and then allow the other sheets to reference that

information using the VLOOKUP function. This allows you to maintain data centrally.

Any updates will automatically update the other sheets.

For example, the table above on the left is used to record interactions with a student.

The student number is recorded each time they have a meeting with a careers adviser.

The table on the right holds student data. Column A holds the student numbers.

If we want to know the school of a student listed in the table on the left, we use the

student number to find the correct row in the master data table on the right and from

there we can find the information we are looking for.

For example, in row 5 in the table on the left we need to find the details for student

number 11376481. We find student number 11376481 in the table on the right and can

see that his school is Arts & Media.

This is exactly what an Excel VLOOKUP does (only faster!)

Note on holding data in Excel

VLOOKUP functions enable you use Excel as a simple relational database. If you think

you want to do this, especially if you plan to hold student or staff personal data, please

talk to the Service Desk who can advise you whether the data you are working with can

be managed within one of our centrally managed business systems (e.g. SITS/CAMS).

Page 4: Comparing and linking tables of data using VLOOKUP

University of Brighton Information Services

Page | 4 Last Updated Faye Brockwell

Steps for using VLOOKUP

1 Prepare your data table

o Sort the data table

o Name the data table

2 Build the VLOOKUP function in the first row

3 Copy the VLOOKUP to the rest of the worksheet

Prepare your data table

Before you can use a VLOOKUP function, you must first prepare your master data

table.

Sort the master data table

The master data table must have unique entries in the first column and the table must

be sorted on the first column in ascending order. To sort the table:

click in the first column of the data table

On the Home tab, click on the Sort & Filter icon

Choose Sort A to Z

Name the master data table

Assigning a name to the master data table makes it easier to build the VLOOKUP

function as you can use the name instead of specifying a range of cells. To name the

table:

Select all of the cells in the data table (you can use your

mouse to do this or click anywhere in the table and press

CTRL+A on a PC keyboard, +A on a Mac keyboard).

Type a name for the data table in the Names box just

above the worksheet and press ENTER.

Spaces are not allowed in Names; use the underscore if

you want to use more than one word.

Tip: You can use the Name Manager on the Formulas tab to edit a named

area on a worksheet (e.g. edit the cell range, delete a name or rename a

named area).

Page 5: Comparing and linking tables of data using VLOOKUP

Comparing and linking tables of data using VLOOKUP

https://staff.brighton.ac.uk/is/training/Pages/Excel/linking.aspx Page | 5

Build the VLOOKUP function

The VLOOKUP function requires 4 pieces of information (arguments):

=VLOOKUP(lookup value, table array, col_index_num, range_lookup)

Lookup_value What from this sheet do you want to find

on the other sheet?

i.e. the cell reference of the cell containing

the item of data in this row on your worksheet

that can be used to find the correct entry in

the master data table

e.g. C2

Table_array Where to look for it

i.e. the name or the absolute cell references

of the data range of the master data table

where you will find what you’re looking for

e.g.

student_table or

$A$1:$E$150

Col_index_num Which column in the other table contains

the data you are looking for

i.e. the column in your master data table

(counting from the left) containing the answer

to your question

e.g. 5

Range_lookup What to do if there is no exact match i.e.

tell you if no exact match has been found or

work with the nearest possible match?

e.g. FALSE or

TRUE

So, the VLOOKUP in cell D5 in the table above left might read:

=VLOOKUP(C5,student_table,5,FALSE)

where student_table is the name of the table on the right.

See the next page for step-by-step instructions for building the VLOOKUP function.

Page 6: Comparing and linking tables of data using VLOOKUP

University of Brighton Information Services

Page | 6 Last Updated Faye Brockwell

To build the VLOOKUP function

1 Click in the cell where you want the answer

to the VLOOKUP to appear

e.g. in our example on the right, click in cell

D5 as the VLOOKUP will be used to find

the school for student 11376481.

2 Type =VLOOKUP(

3 Click on the Build function icon to

open the Function Builder dialogue box.

4 Click in the Lookup_value field and then,

on your worksheet, click on the cell in that

row containing the item of data on your

worksheet that can be used to find the

correct entry on the master data table

e.g. if we were building a VLOOKUP function in cell D5 in the example above, we

would click on the cell C5 to specify that the student number 11376481 should be

used to find the entry we’re looking for in our data table. This is because student

number is the piece of data that both tables have in common.

5 Click in the table_array field and type the name of the data table the was created

earlier (see Name the master data table)

If you do not name the table, use the cell references of the range of cells

containing your data table. Use dollar signs to make these references absolute (eg

$A$1:$E$150). On a Windows computer, pressing the F4 key immediately after

selecting the cell range will put the dollar signs in for you).

6 Click in the Col_index_num field and type the number of the column, when

counting from the left of the table, containing the answer to your VLOOKUP.

E.g. in our example above, if we want to find the school for a particular student, the

school column is the fifth column when counting left to right. So we type 5 in the

Col_index_num of our VLOOKUP.

Note: never use the column letters in a VLOOKUP.

7 Click in the Range_lookup field and type:

FALSE Look for exact matches only. E.g. if your student number doesn’t exist,

the result of the vlookup will show as #N/A

TRUE To return the closest match (next lowest value) and use

that to return an answer. This option is only really used when working

with ranges in the master data table. E.g. tax scales

Note: unless you are working with financial data and number ranges, most

VLOOKUPs use FALSE. Just imagine if you were pulling student data and you

pulled the details of the nearest closest student? Chaos!

8 Click OK.

Page 7: Comparing and linking tables of data using VLOOKUP

Comparing and linking tables of data using VLOOKUP

https://staff.brighton.ac.uk/is/training/Pages/Excel/linking.aspx Page | 7

Copy the VLOOKUP to the rest of the worksheet

Use autofill to copy the VLOOKUP formula down the column

1 Select the cell(s) you want to copy. The fill handle will appear at

the bottom right of the selection.

2 Point at the fill handle until it becomes a cross.

3 Click and drag to copy the data OR Double-click to autofill all rows.

4 Double click on one of the newly-populated

cells within the column to check that the

copied cell references are correct.

Page 8: Comparing and linking tables of data using VLOOKUP

University of Brighton Information Services

Page | 8 Last Updated Faye Brockwell

Excercises

Exercise A

Fill in the gaps in the table above using one of the tables on the next page.

Day Time Student number School

01/11/2011 10:00 11376481

01/11/2011 11:00 09286457

01/11/2011 13:00 09123456

01/11/2011 14:00 10348400

01/11/2011 15:00 10467935

02/11/2011 11:00 10374685

02/11/2011 13:00 11463856

02/11/2011 14:00 09342186

03/11/2011 10:00 09123456

04/11/2011 14:00 11376481

05/11/2011 13:00 10467935

Page 9: Comparing and linking tables of data using VLOOKUP

Comparing and linking tables of data using VLOOKUP

https://staff.brighton.ac.uk/is/training/Pages/Excel/linking.aspx Page | 9

Student number First name Surname DOB School

09123456 Faye Brockwell 11/08/1976 Education

10467935 Jill Shacklock 05/09/1971 Arts & Media

10374685 Brian McCarthy 11/11/1991 Nursing & Midwifery

11376481 Chris Searle 04/06/1990 Arts & Media

10267495 John Roberts 15/02/1989 Architecture & Design

10137401 Jane Dawes 08/07/1990 Engineering

11538467 Paul Hill 01/02/1991 CEM

09286457 Selwyn Percival 22/05/1989 Engineering

10348431 Adam Collett 26/09/1990 SASS

10846815 Dan Burgess 28/08/1990 Business School

09342186 Ben Wheelan 15/03/1987 Arts & Media

09438675 Pat Brown 12/12/1989 CEM

11463856 Ta King 07/10/1986 Education

Student number First name Surname DOB School

09123456 Faye Brockwell 11/08/1976 Education

09286457 Selwyn Percival 22/05/1989 Engineering

09342186 Ben Wheelan 15/03/1987 Arts & Media

09438675 Pat Brown 12/12/1989 CEM

10137401 Jane Dawes 08/07/1990 Engineering

10267495 John Roberts 15/02/1989 Architecture & Design

10348431 Adam Collett 26/09/1990 SASS

10374685 Brian McCarthy 11/11/1991 Nursing & Midwifery

10467935 Jill Shacklock 05/09/1971 Arts & Media

10846815 Dan Burgess 28/08/1990 Business School

11376481 Chris Searle 04/06/1990 Arts & Media

11463856 Ta King 07/10/1986 Education

11538467 Paul Hill 01/02/1991 CEM

Page 10: Comparing and linking tables of data using VLOOKUP

University of Brighton Information Services

Page | 10 Last Updated Faye Brockwell

1 Which table did you use? Why? _________________________________

2 Were you able to complete all the rows in the table? ________________

Exercise B

1 Open exercise file Student Services Example.xlsx

The Interactions worksheet lists a Careers Adviser’s interactions with students.

The Students tab is a list of students by student number.

2 Prepare the data table on the Students worksheet to be used in a VLOOKUP.

3 Create a VLOOKUP in cell D5 on the Interactions worksheet to pull the school for

that student in from the data table on the Students worksheet.

4 Copy the VLOOKUP down column D on the Interactions worksheet to populate

the school for each row.

As this table is not going to be uploaded into another system, there is no need to strip

the VLOOKUP formulae in this exercise.

Exercise C

1 Open exercise file Marks sheet exercise.xlsx

The Marks worksheet lists student marks by module.

The Grades & Check Digits tab is a table of grades and check digits for each

mark.

Note: The table on the Grades & Check Digits worksheet is an example of a marks

sheet using one mark scheme. Do not use this table for real student marks. To obtain a

similar table for your marks scheme, please contact CAMS support.

2 Prepare the data table on the Grades & Check Digits worksheet to be used in a

VLOOKUP.

3 Create a VLOOKUP in cell K2 on the Marks worksheet to pull the grade for that

student’s mark in from the data table on the Grades & Check Digits worksheet.

4 Create a VLOOKUP in cell L2 on the Marks worksheet to pull the check digit for

that student’s mark in from the data table on the Grades & Check Digits

worksheet.

5 Copy the VLOOKUP down columns K and L on the Marks worksheet to populate

the grade and check digit for each row.

Page 11: Comparing and linking tables of data using VLOOKUP

Comparing and linking tables of data using VLOOKUP

https://staff.brighton.ac.uk/is/training/Pages/Excel/linking.aspx Page | 11

Exercise D

1 Open exercise file Finance example using ranges.xlsx

The Payroll worksheet lists staff and their pay scales.

The Payroll Tables tab contains two tables:

The hourly pay rate by pay scale

The rate of income tax by salary

2 Prepare the data tables on the Payroll Tables worksheet to be used in a

VLOOKUP.

3 Create a VLOOKUP in cell D5 on the Payroll worksheet to pull the hourly rate for

that person’s pay scale in from the data table on the Payroll Tables worksheet.

4 Copy the VLOOKUP down column D on the Payroll worksheet to populate the

hourly rate for each row.

5 Create a VLOOKUP in cell G5 on the Payroll worksheet to pull the tax rate for that

person in from the data table on the Payroll Tables worksheet.

6 Copy the VLOOKUP down column G on the Payroll worksheet to populate the tax

rate for each row.

Page 12: Comparing and linking tables of data using VLOOKUP

University of Brighton Information Services

Page | 12 Last Updated Faye Brockwell

Solutions

Exercise A Solution

Most people would choose the bottom of the 2 data tables in the exercise as it is sorted

by student number, thus making it easier to read.

No match can be found for student number 10348400.

Exercise B Solution

1 Open exercise file Student Services Example.xlsx

2 Click on the Students worksheet

3 Sort the data table:

Click on any cell containing text in column A.

Click on the Home tab, click on Sort & Filter and choose Sort A to Z.

4 Name the data table:

Click anywhere in the table of data (a cell containing text)

Press CTRL and A on the keyboard (or the Apple key and A on a Mac keyboard)

Type a name for the table (e.g. student_table) in the Names Box

Press Enter

Day Time Student number School

01/11/2011 10:00 11376481 Arts & Media

01/11/2011 11:00 09286457 Engineering

01/11/2011 13:00 09123456 Education

01/11/2011 14:00 10348400 No match in the table

01/11/2011 15:00 10467935 Arts & Media

02/11/2011 11:00 10374685 Nursing & Midwifery

02/11/2011 13:00 11463856 Education

02/11/2011 14:00 09342186 Arts & Media

03/11/2011 10:00 09123456 Education

04/11/2011 14:00 11376481 Arts & Media

05/11/2011 13:00 10467935 Arts & Media

Page 13: Comparing and linking tables of data using VLOOKUP

Comparing and linking tables of data using VLOOKUP

https://staff.brighton.ac.uk/is/training/Pages/Excel/linking.aspx Page | 13

5 Click on cell D5 on the Interactions tab

6 Type =VLOOKUP(

7 Click on the Build function icon

8 Click in the Lookup_value field and

then click on cell C5

9 Click in the Table_array field and type

the name of your data table (e.g. student_table)

10 Click in the Col_index_num field and type 5.

11 Click in the Range_lookup field and type FALSE and press OK

12 Use the autofill technique to copy the formula down the column (see page 5)

Exercise C Solution

1 Open exercise file Marks sheet exercise.xlsx

2 Name the table on the Grades & Check Digits worksheet (the table is already

sorted on column A) e.g. marks_table

3 Use the autofill technique to copy the formula down the column (see page 5)

4 Select columns K and L

5 On the Home tab, click on

6 On the Home tab, click on the drop-down arrow below the Paste icon

Page 14: Comparing and linking tables of data using VLOOKUP

University of Brighton Information Services

Page | 14 Last Updated Faye Brockwell

7 Click on Paste Values icon.

8 Double click on one of the cells in column K or L to check that the VLOOKUP

function has been removed.

Exercise D Solution

1 Open exercise file Finance example using ranges.xlsx

2 Name the Hourly Rate table (e.g. hourly_rate_table)

3 Name the Tax table (e.g. tax_table)

4 Use the autofill technique to copy the formula down the column (see page 5)

5 Use the autofill technique to copy the formula down the column (see page 5)