Fun With Formulas
Fun With Formulas
Scroll down after selecting item from menu -- desired instructions are at the bottom of the screen
What is a formula?
Anatomy of a formula
Inserting formulas in a worksheet
Viewing and finding formulas
Copying, pasting, and dragging formulas
Relative and absolute cell addresses in formulas
Names in formulas
What is a Formula?
Formula Result Formulas are commands used to manipulate data in Excel. They are introduced in a cell by using the '=' symbol.
=2+3 5 For example, =2+3 makes Excel add 2 and 3 together, giving us "5" as a result.
You can use '=' to make Excel calculate the result of most common numerical operations (and some string operations).
But the true strength of formulas (also called functions) are special commands programmed by Excel. You summon these formulas by calling their name after the '=' sign.
=SUM(2,2,1) 5 For example, theSUM function sums up all numbers separated by commas contained in the formula (delimited by parentheses) and returns the result.
The result of a formula, what the formula returns, might be a number or a string of text or something else entirely.
For the purposes of this tutorial, 'formulas' will refer to the special commands programmed by Excel.
Back to Top
Anatomy of a Formula
1
2 Formulas follow a specific structure. First, there is the '=' symbol and the name of the function being called.
3 Next, enclosed in parenthesis, you have the arguments of a formula, separated by commas.
Some arguments might be optional - when manually entering a formula, optional arguments will be indicated by brackets.
Formula Result
=SUM(2,3) 5
=SUM(2,3,1) 6 Formulas generally require specific types of argument: numbers, text, cell ranges, boolean values, etc.
=SUM(2,3,"cat") #VALUE! For example, the sum formula uses numbers as its arguments, it won't work with text. It makes sense. How would you add up "cat" with 2 and 3?
=SUM(2,B25) 3 However, as long as the content of a cell is of the type needed by the argument, formula arguments work with cell addresses. Here, cell B25 contains the number 1, so the
formula adds 2 and 1. If the value located at a specified cell address changes, the formula results will automatically update!
=SUM(2,B25:B27) 8 As long as all the cells contain the right type of value, cell ranges can also be used in formula arguments. In this example, B25:B27 means "start at B25 and keep going until you
reach B27". This means that the formula adds up 2, the contents of B25 (1), the contents of B26 (2), and the contents of B27 (3).
If cells in the cell range contain data of a different type from what is accepted by the argument, the formula will either ignore the incorrect input or fail.
Formula Result
Theleft function has two arguments. First, it requires some sort of text. In Excel formulas, text (also called strings) are enclosed in quotation marks. The second argument is
=LEFT("Excel is fun") E optional. We provide the number of characters to extract in the string, starting from the left. If we don't specify a number of characters, "1" is chosen by default. This formula
returns text. In the example, the letter in position 1 is extracted from "Excel is fun": "E".
=LEFT("Excel is fun",5) Excel By supplying the optional argument, we tell Excel to return the first five letters in "Excel is fun", starting from the left.
=LEFT("Excel is fun",2+3) Excel Excel is perfectly happy with performing a mathematical operation in an argument and using its result.
As long as it returns a value of the right type, a formula can be used as the argument of another formula. For example, here we are using the string "Excel is fun" as our first
=LEFT("Excel is fun",sum(2,3)) Excel argument. The next argument must be the number of characters we want to extract from the string. Instead of a number, we use sum(2,3) to add together 2 and 3. That formula
returns the number 5, which is then used to specify the number of characters to return in the left formula.
With arguments being able to contain cell addresses, cell ranges, mathematical operations, and other nested formulas, complexity quickly rises. It may be easiest to understand
=LEFT("Wow"&A37,sum(B25:B27)+1) WowForm complex formulas by separately evaluating each argument - so remember to look for the commas. You could also try creating the simplest version of a formula before modifying
its arguments for the desired effect.
Back to Top
Inserting Formulas in a worksheet
Allows you to manually input a formula in Excel - Excel will try to guess the name of the formula as you type it. It will give a brief reminder of what should be inputted for each
Select a cell. Write = argument of the function. Optional arguments are given in brackets. Instead of manually typing in a cell address, you can select the desired cell or cells. Use quotation marks to
enter text as an argument.
While actively manually typing in a formula, Excel will color code cell addresses in your formula, and will correspondingly color the cells at the specified addresses.
Select a cell. Write '= Creates a formula without activating it, displays a formula without activating it. You won't get contextual help with building the formula, but you won't have to deal with error
messages. When finished, remove the apostrophe to activate the formula.
Select a cell. Formulas - Function Library Click on "Insert Function" to use a wizard to enter a formula. You can click on the arrows to select cells instead of manually inputting cell addresses. If you don't know what
formula might fit your needs, you can also use Insert Function to search the formula library.
Back to Top
Viewing and Finding Formulas
Double-clicking on a cell containing a formula Enables you to edit the formula. Will activate matching colors for the cell addresses and the concerned cells if the formula has references (addresses) to cells.
Formulas - Formula Auditing Select the cell containing a formula you would like to trace, and click on "Trace Precedents" or "Trace Dependents" to view locations of cells involved in a formula, as well as cells
belonging to formulas nested inside other formulas. Click on "Remove Arrows" to clear this view.
Formulas - Formula Auditing Click on "Show Formulas" to toggle from viewing results of formulas, to viewing the formula itself in all cells of the worksheet. WARNING: this might have an irreversible impact
on the formatting of your worksheet.
Click on a cell - F5 Click on "Special" and select "formulas" to temporarily select all cells containing formulas in your worksheet. You can hit "enter" to navigate from cell to cell, format all cells that
have formulas, etc.
or
Home - Editing
Back to Top
Copying, Pasting, and Dragging Formulas
About copy-pasted formulas When copy-pasting a formula that contains cell addresses, the formula will automatically change references to rows for each row where it is pasted, and will change references to
columns for each columns where it is pasted.
1 =A108 For example, copying the formula in cell B108 (=A108) into the cells below will make the formula automatically jump rows: =A109 for B109, and =A110 for B110
2 =A109
3 =A110
Ctrl-C and Ctrl-V Keyboard shortcuts for copy-pasting. Works with formulas.
Right click on cell - Copy or Paste Copy-pasting. Works with formulas. The paste menu will have a few options - choose carefully.
Dragging the fill handle Select a cell and drag the fill handle to copy-paste. Works with formulas.
Double-clicking on the fill handle If working with a range of formulas, such as a table, double-clicking on the fill handle will fill out the rest of the row or column with the formula.
To transform formulas back into values Select the formula or formulas. Copy using your favorite method. While the selection is still active, paste in place by selecting "paste as values". If using Ctrl-V to paste, you will
temporarily be able to select "paste as values" from a tiny pop-up menu. Your formulas are gone, replaced by values.
Back to Top
Relative and Absolute Cell Addresses in Formulas
When copy-pasting a formula that contains cell addresses, the formula will automatically change references to rows for each row where it is pasted, and will change references to
Cat columns for each columns where it is pasted.This is not always desired behavior and can be especially problematic in formulas that have ranges as arguments.
1 In a cell address, the $ symbol before a column and/or before a row tells Excel that when the formula is copy-pasted in a different location, it must not adjust the formula for the
number of columns or rows that it has been moved. This is known as an absolute address.
2 For example, let's pretend we want to gradually expand the number of characters revealed in the word "Cat" in B139 by using the numbers supplied in B140 to B142.
3
Copy-Pasted Formula - Relative Result If we write our formula normally and copy-paste it, the location of the text (the first argument in the left function) moves down a row every time - not the behavior we wanted. Try
double-clicking on B144, B145, and B146 to see what happened to the formula.
=LEFT(B139,B140) C
=LEFT(B140,B141) 1
=LEFT(B141,B142) 2
Copy-Pasted Formula - Absolute Result If instead we use the "$" symbol before the column and row of the location of the text, the formula will correctly refer to B139 for the text argument even when copy-pasted. Try
clicking on B148, B149 and B150 to see what happened to the formula.
=LEFT($B$139,B140) C
=LEFT($B$139,B141) Ca
=LEFT($B$139,B142) Cat
Back to Top
Names in Formulas
You can assign nicknames to cells, and use these nicknames instead of the cell addresses in formulas.
Right Click - Define Name
or
Formulas - Defined Names
My name is Miow For example, we've assigned the name "Miow" to cell A162.
Formula Result
LEFT(A162,8) My name The formula works whether we use the cell address or our nickname for the cell.
LEFT(Miow,8) My name
Instructions
You left Dalhousie a year ago in order to start your own pigeon raising business. You had great hopes for your pigeons. Unfortunately, the wind tore a hole in the
roof of the shack where you were keeping them and despite your cries and your pleas, they all escaped.
Your insurance company is asking a lot of questions, so you decide to use Excel to calculate your losses.
1 Each pigeon was worth $2 of profit. You want to calculate your lost of profit. Start by entering the following formula in cell D5 of the Exercise worksheet: =C5*2
2 Copy-paste the formula in the rest of the column - all the way to row 19.
3 Double click on a few of the cells. What do you notice about the cell address?
Let's find the total number of escaped pigeons. In cell C20, write: =sum( and click and drag the mouse to select rows C5 to C19. The formula should automatically fill in to
4 reflect =sum(C5:C19 . Hit enter.
5 Let's highlight the total number of escaped pigeons. In cell H5, enter a formula that will give us the total number of escaped pigeons.
6 Let's find the total amount of profit loss. In cell D20, manually type in =sum(D5:D19) and hit enter.
7 Let's highlight the total profit loss. In cell H9, enter a formula that will give us the total profit loss.
You realize that you forgot to take taxes into account. Add tax by adding a 1.15 tax rate multiplication in each cell in range D5:D20. (Hint: fix the formula in D5, then copy-
8 paste).
The insurance company calls you. Apparently, the profit loss per pigeon is actually a catastrophic 3.5, but the tax rate is only 14%. They might call you with another revision
later. All these updates are getting in your way -- you want to get this done and start rebuilding your life!
We'll start by entering a formula that refers to the constants in cells C2 and E2 to make sure that everything works okay, and then we'll update the profit loss and tax rate.
14 Give the name "profitLoss" to cell C2 and the name "tax" to cell E2.
15 Enter a formula in cells F5 to F20 that uses cell names instead of cell addresses to calculate loss profit.
Number of
Profit loss by Profit loss by Profit loss by
Minutes escaped
minute minute minute
elapsed pigeons by
(version 1) (version 2) (version 3)
minute
1 7
2 10
3 21
4 85
5 42
6 91
7 83
8 67 Average lost pigeons a minute
9 74
10 75
11 92
12 45 Highest profit loss in a minute
13 72
14 41
15 84
Total:
Total lost pigeons
Formulas
What is a Formula?
Formula Result Formulas are commands used to manipulate data in Excel. They are introduced in a cell by using the '=' symbol.
=2+3 5 For example, =2+3 makes Excel add 2 and 3 together, giving us "5" as a result.
You can use '=' to make Excel calculate the result of most common numerical operations (and some string operations).
But the true strength of formulas (also called functions) are special commands programmed by Excel. You summon these formulas by calling their name after the '=' sign.
=SUM(2,2,1) 5 For example, theSUM function sums up all numbers separated by commas contained in the formula (delimited by parentheses) and returns the result.
The result of a formula, what the formula returns, might be a number or a string of text or something else entirely.
For the purposes of this tutorial, 'formulas' will refer to the special commands programmed by Excel.
Anatomy of a Formula
1
2 Formulas follow a specific structure. First, there is the '=' symbol and the name of the function being called.
3 Next, enclosed in parenthesis, you have the arguments of a formula, separated by commas.
Some arguments might be optional - when manually entering a formula, optional arguments will be indicated by brackets.
Formula Result
=SUM(2,3) 5
=SUM(2,3,1) 6 Formulas generally require specific types of argument: numbers, text, cell ranges, boolean values, etc.
=SUM(2,3,"cat") #VALUE! For example, the sum formula uses numbers as its arguments, it won't work with text. It makes sense. How would you add up "cat" with 2 and 3?
=SUM(2,B17) 3 However, as long as the content of a cell is of the type needed by the argument, formula arguments work with cell addresses. Here, cell B17 contains the number 1, so the
formula adds 2 and 1. If the value located at a specified cell address changes, the formula results will automatically update!
=SUM(2,B17:B20) 8 As long as all the cells contain the right type of value, cell ranges can also be used in formula arguments. In this example, B17:B20 means "start at B17 and keep going until you
reach B20". This means that the formula adds up 2, the contents of B17 (1), the contents of B18 (2), and the contents of B19 (3).
If cells in the cell range contain data of a different type from what is accepted by the argument, the formula will either ignore the incorrect input or fail.
Formula Result
Theleft function has two arguments. First, it requires some sort of text. In Excel formulas, text (also called strings) are enclosed in quotation marks. The second argument is
=LEFT("Excel is fun") E optional. We provide the number of characters to extract in the string, starting from the left. If we don't specify a number of characters, "1" is chosen by default. This formula
returns text. In the example, the letter in position 1 is extracted from "Excel is fun": "E".
=LEFT("Excel is fun",5) Excel By supplying the optional argument, we tell Excel to return the first five letters in "Excel is fun", starting from the left.
=LEFT("Excel is fun",2+3) Excel Excel is perfectly happy with performing a mathematical operation in an argument and using its result.
As long as it returns a value of the right type, a formula can be used as the argument of another formula. For example, here we are using the string "Excel is fun" as our first
=LEFT("Excel is fun",sum(2,3)) Excel argument. The next argument must be the number of characters we want to extract from the string. Instead of a number, we use sum(2,3) to add together 2 and 3. That
formula returns the number 5, which is then used to specify the number of characters to return in the left formula.
With arguments being able to contain cell addresses, cell ranges, mathematical operations, and other nested formulas, complexity quickly rises. It may be easiest to understand
=LEFT("Wow"&A30,sum(B17:B20)+1) WowForm complex formulas by separately evaluating each argument - so remember to look for the commas. You could also try creating the simplest version of a formula before modifying
its arguments for the desired effect.
Select a cell. Write '= Creates a formula without activating it, displays a formula without activating it. You won't get contextual help with building the formula, but you won't have to deal with error
messages. When finished, remove the apostrophe to activate the formula.
Select a cell. Formulas - Function Library Click on "Insert Function" to use a wizard to enter a formula. You can click on the arrows to select cells instead of manually inputting cell addresses. If you don't know what
formula might fit your needs, you can also use Insert Function to search the formula library.
Formulas - Formula Auditing Select the cell containing a formula you would like to trace, and click on "Trace Precedents" or "Trace Dependents" to view locations of cells involved in a formula, as well as cells
belonging to formulas nested inside other formulas. Click on "Remove Arrows" to clear this view.
Formulas - Formula Auditing Click on "Show Formulas" to toggle from viewing results of formulas, to viewing the formula itself in all cells of the worksheet. WARNING: this might have an irreversible impact
on the formatting of your worksheet.
Click on a cell - F5 Click on "Special" and select "formulas" to temporarily select all cells containing formulas in your worksheet. You can hit "enter" to navigate from cell to cell, format all cells that
have formulas, etc.
or
Home - Editing
About copy-pasted formulas When copy-pasting a formula that contains cell addresses, the formula will automatically change references to rows for each row where it is pasted, and will change references to
columns for each columns where it is pasted.
1 =A106 For example, copying the formula in cell B106 (=A106) into the cells below will make the formula automatically jump rows: =A107 for B107, and =A108 for B108
2 =A107
3 =A108
Ctrl-C and Ctrl-V Keyboard shortcuts for copy-pasting. Works with formulas.
Right click on cell - Copy or Paste Copy-pasting. Works with formulas. The paste menu will have a few options - choose carefully.
Dragging the fill handle Select a cell and drag the fill handle to copy-paste. Works with formulas.
Double-clicking on the fill handle If working with a range of formulas, such as a table, double-clicking on the fill handle will fill out the rest of the row or column with the formula.
To transform formulas back into values Select the formula or formulas. Copy using your favorite method. While the selection is still active, paste in place by selecting "paste as values". If using Ctrl-V to paste, you will
temporarily be able to select "paste as values" from a tiny pop-up menu. Your formulas are gone, replaced by values.
Cat When copy-pasting a formula that contains cell addresses, the formula will automatically change references to rows for each row where it is pasted, and will change references to
columns for each columns where it is pasted.This is not always desired behavior and can be especially problematic in formulas that have ranges as arguments.
1 In a cell address, the $ symbol before a column and/or before a row tells Excel that when the formula is copy-pasted in a different location, it must not adjust the formula for the
number of columns or rows that it has been moved. This is known as an absolute address.
2 For example, let's pretend we want to gradually expand the number of characters revealed in the word "Cat" in B138 by using the numbers supplied in B139 to B141.
3
Copy-Pasted Formula - Relative Result If we write our formula normally and copy-paste it, the location of the text (the first argument in the left function) moves down a row every time - not the behavior we wanted. Try
double-clicking on B143, B144, and B145 to see what happened to the formula.
=LEFT(B138,B139) C
=LEFT(B139,B140) 1
=LEFT(B140,B141) 2
Copy-Pasted Formula - Absolute Result If instead we use the "$" symbol before the column and row of the location of the text, the formula will correctly refer to B138 for the text argument even when copy-pasted. Try
clicking on B147, B148 and B149 to see what happened to the formula.
=LEFT($B$138,B139) C
=LEFT($B$138,B140) Ca
=LEFT($B$138,B141) Cat
Names in Formulas
You can assign nicknames to cells, and use these nicknames instead of the cell addresses in formulas.
Right Click - Define Name
or
Formulas - Defined Names
My name is Miow For example, we've assigned the name "Miow" to cell A162.
Formula Result
LEFT(A162,8) My name The formula works whether we use the cell address or our nickname for the cell.
LEFT(Miow,8) My name