So far, we've referred to cells by their column and row - for example A1, F58 and so on. Excel also lets you give cells names of your own. This can be useful when writing formulas, instead of typing the cell reference you give the cell a meaningful name and then use that name in the formula. So, instead of:
=C3*B2
You could give cell B2 the name VAT and have a formula like
=C3*VAT
Names can also be applied to cell ranges.
We've already had a look at absolute and relative cell references in the autofill section, note that cell names will be absolute references. This can be handy when you're autofilling formulas.
Have a look at the spreadsheet below, we're going to put a formula in cell E6 that will calculate the total pay for each employee. Since we'll use autofill to copy the formula down, we need to make the cells containing pay rates absolute references, so the formula would be:
=D6*$D$3
if we weren't using names.
Instead, we'll give cell D3 the name pay.rate and use this in the formula.
You can use autofill to copy this formula down to calculate total pay for the other employees.
You can give names to cell ranges in the same way - this could be useful for selecting data for charts or for lookup functions.
If you want to change or delete a name:
By default, the scope of these names is workbook. This means you can use the names to refer to these cells/ranges from any sheet in the workbook. You can change the scope to worksheet, in which case you wouldn't be able to use it in other sheets since its use is restricted to the current sheet. Names have to be unique in their scope, so you can't have another sheet in the workbook with a cell called pay.rate.
The If function lets you choose what action to take depending on whether a condition is met. The basic format is:
IF (Something is True, then do something, otherwise do something else)
For example, we could check whether a score is greater than or equal to 50 (our condition) then assign a pass or fail grade
Copying the formula down, we would get results for everyone:
Comparison | Operator | Example | Meaning |
---|---|---|---|
Equal to | = | A1=B1 | A1 equals B1 |
Less than | < | A1<B1 | A1 is less than B1 |
Greater than | > | A1>B1 | A1 is greater than B1 |
Greater than or equal to | >= | A1>=B1 | A1 is greater than or equal to B1 |
Less than or equal to | <= | A1<=B1 | A1 is less than or equal to B1 |
Not equal to | <> | A1<>B1 | A1 is not equal to B1 |
The VLOOKUP function can be used to find information in a specified row in a table. For example you might look up someone's name in a telephone directory to find their phone number. This function looks quite complicated but it can be very useful once you get the hang of it. The basic format is:
=VLOOKUP (value you want to look up, cell range, column where you want the value returned, FALSE for exact match or TRUE for approximate match)
Here we have a table B8:D14 showing name, hours and total pay. I want to be able to type a name into cell C2 and have the total pay for that person shown in cell C3. The VLOOKUP function can do this, but it needs 4 pieces of information for it to work:
So, to enter the function:
It's possible to use named ranges in the formula - I could have selected B8:D14 and given it the name pay for example. Then the function would be:
=VLOOKUP(C2,pay,3,FALSE)
When you sort data, you put it into an order that makes it easier to use. For example we could put a list of products in alphabetical order or order a list of prices from lowest to highest.
Here's a list of 8 numbers, we'll order them from highest to lowest.
You can also use this to sort lists of words or dates.
The above method is fine if you've only got one column of data, but we've often got data across multiple columns as below:
Suppose we want to sort alphabetically by surname, we would use the same method as above but what happens to the data in the other columns - will it also be reordered?
As you can see, the other columns have been sorted along with the surname column. But there are 2 people with the surname Jones and we would prefer them to be sorted alphabetically by forename - Fred should be before Margaret.
We can do this by adding sorting levels. The first level will be Surname then the next level Forename will be used for records whose surnames match.
The table is now sorted alphabetically by Surname, then by Forename:
Sometimes it's necessary to select the range you want sorted, for example if there's a row at the bottom of the table that should always stay at the bottom. You might have noticed on the Custom Sort dialog box that there's an option to include a header row:
This stops the top row with Forename, Surname, Test 1 and so on being sorted with the rest of the data. But what happens when there's a row at the bottom that shouldn't be sorted?
If you click on cell C3 and sort by surname, the bottom row is included with the other rows:
To prevent this, click and drag to select the cell range that you want to be sorted before choosing the sort method. In the above example, this would mean selecting the cells B2:G8 before sorting (this includes a header row).
The data is now sorted correctly.
Excel spreadsheets come in the form of workbooks which can contain several worksheets. You can add additional worksheets and rename them to give you an idea of what's on each sheet. You can also reference cells on other worksheets, although you would obviously have to make it clear which worksheet and cell you were referencing.
The button to add a worksheet is at the bottom left of the spreadsheet, click this and another sheet will be created. Currently there is one sheet in this workbook, called Sheet1. Click this and there will be another sheet called Sheet2.
We'll rename these sheets, one is for data relating to 2018 and the other is for 2019 so we'll just call them the years.
Click on the 2018 worksheet and enter the data as below:
Then click on the 2019 sheet and enter the following:
We want to get the profit from cell C6 in the 2018 sheet and put it into cell C8 in the 2019 sheet, but if we type =C6 in C8 it will take the C6 value from the 2019 cell which is blank. So how can we do this?
To reference a cell in another sheet, put the sheet name followed by an exclamation mark before the cell reference.
You can prevent other people making changes to your worksheet by protecting it. This can stop others accidentally deleting parts of the sheet, changing formulas etc. You can also choose cells that other people are allowed to edit and protect the rest of the sheet. There are 2 steps to this:
Using the sheet with a VLOOKUP function as an example, I want to allow people to enter a name to find out the total pay for that employee but I want to protect the rest of the sheet so that nobody can change it.
The sheet is now protected, if anyone tries to enter data in a cell other than C2, they will get an error message