Formulas and Functions handout

1
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
Contents
FORMULAS AND FUNCTIONS ........................................................................................ 3
Arithmetic formulae ...................................................................................................... 3
Error Messages ............................................................................................................. 3
Entering formulae ......................................................................................................... 4
Addition ......................................................................................................................... 4
Subtraction .................................................................................................................... 4
Building formulae using mouse ...................................................................................... 5
Multiplication ................................................................................................................ 5
Division .......................................................................................................................... 5
More complicated formulae ......................................................................................... 6
Editing formulae ........................................................................................................... 7
Using Auto fill ............................................................................................................... 7
Working with Functions ................................................................................................... 8
SUM Function ............................................................................................................... 8
The Average Function .................................................................................................. 9
The Max Function ......................................................................................................... 9
The MIN Function ......................................................................................................... 9
The COUNT Function ................................................................................................... 9
Other Useful Formulas ............................................................................................... 10
Age Formula ................................................................................................................ 10
Entering today’s date ................................................................................................. 10
Relative and Absolute Cell Referencing ....................................................................... 11
Relative References ................................................................................................... 11
Absolute References .................................................................................................. 11
Comparison Operators .................................................................................................. 12
The Logical IF Function ................................................................................................. 13
The Paste Function button ............................................................................................ 14
Consolidation exercise for Formulas / Functions ....................................................... 15
Outcome answers for exercise.................................................................................. 17
Outcome with formulas: -........................................................................................... 18
Odds & Ends ................................................................................................................... 19
Paste special ............................................................................................................... 19
Linking Cells ............................................................................................................... 19
Freezing and Unfreezing Rows and Columns.......................................................... 19
Protection/Unlocking cells......................................................................................... 21
Data Validation ............................................................................................................ 22
Creating a drop down list........................................................................................... 23
Custom Lists ............................................................................................................... 24
Conditional Formatting .............................................................................................. 25
Consolidation exercise for Odds & Ends ..................................................................... 26
Outcome for exercise ................................................................................................. 27
FORMULAS AND FUNCTIONS
2
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
Arithmetic formulae
The two main uses for Excel are to store and analyse information and to make
calculations. Once you have entered the information, you then have to enter the
formulae to work out what it is you want to know. Excel does not need to know the
content of the cell to work out formulas it uses the Cell reference ie:- B1, C4 etc
The buttons for entering the mathematical signs are on your number pad as
follows:-
/
=
Division
* =
Multiplication
- =
Subtraction
+ =
Addition
Error Messages
When you work with formulae you occasionally get error messages. The table
below gives examples of the main error messages and their meanings. If you get
an error message appear you should be able to work out where the error is and
correct it by editing the formula in the formula bar.
Error
message
Meaning
#VALUE!
One of the cells involved in the calculation contains text instead of a
number.
#REF!
One of the cell references in the formula is not valid — you may
have pasted moving cells into cells that are referred to by other
formulae.
#DIV/0!
The denominator in a division formula is zero — you cannot divide
by zero.
########
The cell is not wide enough to display its contents.
3
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
Entering formulae
Select the cell in which you want the answer to your calculation to appear. Type
an equals sign = this indicates that a formula follows. Enter the formula using the
cell references for the cells that are part of the calculation.
NB: - Excel does not mind whether you use upper case or lowercase letters – B6
is the same as b6.
There are two ways of entering formulae:1.
Enter formulae by typing the cell references
2.
Building the formulae by typing operators and clicking the appropriate
cells with the mouse.
Examples of simple formulae:Active cell
reference
Formula bar
Addition
Using the table of information above – if you wished to add the contents of cell B3
to the contents of cell C3 displaying the answer in cell D3. First ensure that cell
D3 is selected then type:
=b3+c3 press enter to confirm entry.
Note on the example above cell D3 has the solution to the formula entered but
you can see the formula applied to this cell by looking in the formula bar.
Subtraction
If you wanted to subtract the contents of cell C4 from the contents of cell B4,
displaying the answer in cell D4.
First make sure that cell D4 is selected.
Type:
=b4-c4
Press enter to confirm entry.
4
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
Building formulae using mouse
You can build formulas in steps by typing in the operators such as =, +, -, /, * and
using the mouse to click on the cell references you wish to use.
Multiplication
To multiply the cells of B5 and C5 so the answer displays in cell D5.
First ensure cell D5 is selected then enter the following:
= Then using the mouse click in cell B5.
C5.
Type * then using mouse click in cell
Check the formula in the formula bar and then press enter to confirm.
Division
To divide the contents of cell B6 by the contents of cell C6.
First click in the cell you want the answer to appear in (D6) then enter the
following:=Using the mouse click in cell B6 – type / then using mouse click in cell C6.
Press enter to confirm entry.
5
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
More complicated formulae
There will be times when you want to use several operators – adding some
quantities, subtracting others also using multiplication or division.
Excel does not work through a formula from left to right. Excel has a specific
working order for calculating formulae. The mathematical term for this is called
BODMAS – Brackets over Division Multiplication Addition Subtraction.
See table below:Priority
Worked out
first
Worked out
last
Symbol
(
Operation
)
Anything enclosed in
brackets
* /
Multiplication, division
+ -
Addition, subtraction
Therefore if you are entering a formula you have to think what you would like
Excel to work out first and enter these figures in brackets:For example if you wanted to perform the following calculation 10+20+5*3 Excel
would calculate the wrong answer because it would multiply 5 by 3 first then add
10 and 20 to the answer. It therefore needs to be entered within brackets such as
(10+20+5)*3. This way Excel knows what to calculate first.
So to apply this to cell referencing on an Excel worksheet you would need to
select the cell you wished the answer to be displayed in then type or build your
formula using the appropriate cells. The example below demonstrates this:-
6
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
Editing formulae
There are two ways of editing formula.
formula. :1.
2.
First select the cell that contains the
Double click cell so your cursor is flashing within it then edit the formula
using the normal editing keys such as Delete, Backspace or arrows etc.
Click on the Formula bar and edit in the usual way.
To confirm your changes either click on the green tick or press the enter key.
Using Auto fill
Auto fill provides an easy way to copy a cell or range of cells into adjacent cells.
For example days of the week, months, formulas and numbers can be auto filled
across a range of cells.
To do this first enter your first entry, for example Type Monday into cell A1. Note
on the example below there is a small black square in the bottom corner of your
cell this is called a fill handle:Fill handle
Using your mouse hover over this square until your mouse cross changes to a
small black cross then holding your left mouse button down drag across the cell
range and notice that Excel auto fills the next series – Tuesday, Wednesday etc.
If there is a formula in the original cell selection, it is this that will be copied and
not the value calculated by the formula.
Note: that it does auto fill abbreviations too. For example if you type Mon then it
will fill in Tues, Wed etc.
Auto filling numbers:This works in the same way as above except if you want to fill in multiples of 1
then you hold the Ctrl key down whilst dragging the fill handle across the range of
cells. However if you want to fill in a series for example 3,6,9,12 you need to
enter the first two numbers in the sequence then select (highlight) those two cells
before using the auto fill handle.
Select first two sequence cells
before you use fill handle
7
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
Working with Functions
SUM Function
Manually entering the SUM Function
The SUM function is used to add a range of numbers together.
Click into the destination cell, (where you want the total to appear). See example
below.
=SUM(B2:D2)
This will add the contents of cell B2 and D2 and all cells between them, (ie, C2).
Press enter on the keyboard to complete the formula.
Using Auto sum
The SUM function is one of the most regularly used functions.
has included an Auto sum button on the Standard toolbar.
Excel
To use auto sum: • Click in the destination cell where you wish your total to appear.
• Click on the Auto sum button.
• Ensure the marching ants are around the correct range of cells. You can alter
these by highlighting the correct range with your mouse. See example below
for clarification.
• Press enter on your keyboard or click the green tick to complete the formula
• Use Auto fill (fill handle) to copy the formula to the remaining total.
8
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
The Average Function
The average function is used to calculate the average for a list of numbers. It will
add the numbers together and divide by how many numbers there are, this is
called the Mean average.
Click onto the destination cell where you want your answer to appear. Then type:
=AVERAGE(B2:D2)
Press enter on the keyboard to complete the formula.
The Max Function
The MAX function is used to find the highest number in a list of numbers.
Click onto the destination cell where you want your answer to appear. Then type:
=MAX(B2:B15)
Press enter on the keyboard to complete the formula.
The MIN Function
The MIN function is used to calculate the lowest number from a list of numbers.
Click onto the destination cell where you want your answer to appear. Then type:
=MIN (B2:B15)
Press enter on the keyboard to complete the formula.
The COUNT Function
The COUNT function is used to calculate how many entries are within a list of
numbers.
Click onto the destination cell where you want your answer to appear. Then type:
=COUNT (B2:B15) (If counting text entries you need to enter =COUNTA)
Press enter on the keyboard to complete the formula.
NB: All of the above functions can be used using the Autosum button.
Ensure the marching ants are around the correct range of cells, then click
on the arrow at the side of the Autosum button and select your desired
function.
9
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
Other Useful Formulas
Age Formula
To Work out a persons rounded age then enter their date of birth into cell A1 then
enter the following formula:
=DATEDIF(A1, TODAY(), "y")
Alternatively have today’s date in one cell, their d of b in another and take d of b
away from today’s date and divide by 365.25. =(a1-a2)/365.25.
Entering today’s date
If you wish to enter today’s date so that the date will automatically update to the
correct date when you next open your worksheet:
Type
=today()
To enter today’s date as a static date so you can autofil
Press the Ctrl key and the semi colon on your keyboard.
To show the date as text for the day of the week
Type
=text(A2,”dddd”) press enter then autofil
the days down.
10
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
Relative and Absolute Cell Referencing
When you create a formula, cell references direct Excel where to look for data or
values. There are two ways in which data and values in cells are accessed or
referred to, i.e. using relative references or absolute references in a formula.
Relative References
Relative cell references are used when the cells containing data or values you
want to use are positioned relative to the cell containing the formula. For
example: In the diagram, B2 and C2 are
positioned relative to D2. Once the
formula in D2 has been entered the
formula
can
be
auto
filled
(replicated), to D3, because they
are relative cells Excel automatically adjusts the references in the copied formula
to refer to the different cells.
Absolute References
Absolute references are less frequently used in simple spreadsheets than relative
references. An absolute reference does not adjust in any way when you replicate
(auto fill) the formula. For the example in the diagram below, if you wanted to
force excel to look at B3 each time you would put a $ against the B and the 3,
=$B$3.
To
identify
where
an
absolute reference has been
used, part of the formula will
contain a $ sign.
This
means that when you auto
fill the formula to the other
cells, due to the absolute
reference being used, it will
alter the first part of the
formula to suit (see the
example) i.e. b8 and then b9
but the end of the formula will always relate back to b3 because of the $ signs.
11
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
Comparison Operators
The following is a table of comparison operators and their definitions.
Operator Description
=
Equals
>
Is greater than
<
Is less than
>=
Is greater than or equal to
<=
Is less than or equal to
<>
Does not equal
In the example below if you wanted to use a comparison operator to find out if the
contents of cell A1 is greater than 15 then select the cell you want your answer to
appear in (B1) and enter =A1>15 then press enter you should get either a TRUE
or FALSE display depending on the content of A1. Try altering the content of A1
from 10 to 25 and see if your formula changes.
12
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
The Logical IF Function
The IF function is one of the most frequently used logical functions. The IF
function allows you to test for a condition and then carry out an action depending
on whether the condition is found to be true or false. There are three arguments
in an IF function:
(1)
(2)
(3)
=IF(logical_test,value_if_true,value_if_false)
(1)
For Example:- If the value in (E4 is less than 80) then the value to be
(2)
(3)
displayed in (G4 is NO) otherwise the value to be displayed is (YES).
Occasionally you may need to refer to a certain cell on the spreadsheet for your
true and false values. This is where you can use absolute cell referencing as part
of your formula. As you can see on the example below Cells A10 and A11 have
YES and NO which is to be used in the formula. Remember if you which to direct
Excel to a certain cell you must use the $ sign for the Cell reference. Otherwise
Auto fill will not work.
13
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
The Paste Function button
You can use the paste function button on the toolbar to assist you in
the
use of functions. All the functions and many more are listed in this function
button. Click in the destination cell where you want your answer to be then click
the paste function button. We are going to use the IF function as an example.
The following box will appear where you can select the IF function from the most
recently used category or if it does not appear then click in the All category and
scroll to search. Once selected, click OK.
•
Enter in the logical test condition; you can use the selector button at the
right hand end of the logical test box to click onto the Cells on your
spreadsheet.
Selector Button
•
Then click the selector button again to return to the box above. Then enter
in your True and False values then OK.
•
Your formula will then be complete.
14
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
Consolidation exercise for Formulas / Functions
1.
Open Working with functions workbook from the Training on Schrödinger
K: Folder for your machine, ECDL Module files, Module 4 Coursework folder
and save using a unique filename.
Or alternatively enter the following onto a new workbook.
2.
On sheet 1 in cell C14 use the appropriate formula/function to work out the
total for Week 1.
3.
Replicate the formula in Cell C14 to D14:F14.
4.
In cell G4 Use the appropriate formula/function to work out the Total from
Week 1 – Week 4 for Student Brennan.
5.
Replicate the formula in Cell G4 to cell range G5:G12.
6.
In order to work out the Balance the formula is Total Due minus Total.
Please enter the formula into Cell H4. Then replicate it to cell range
H5:H12.
7.
In cell C16 please work out the average for Week 1. Replicate the formula
to D16:F16.
8.
In cell C17 enter a formula/function to work out the highest amount for
Week 1 and replicate the formula to D17:F17.
9.
In cell C18 enter a formula/function to work out the lowest amount for Week
1 and replicate the formula to D18:F18.
15
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
10. In cell C19 enter a formula/function to work out the No of payments for
Week 1 and replicate the formula to D19:F19.
11. In cell C21 add an appropriate formula/function that states if the amount in
cell C14 is greater than 170 then refer to cell A22 if it is not then refer to cell
A21, (ensure that if you copy the formula it still refers to cell A22 and cell
A21).
12. Replicate the formula in cell C21 to cell range D21:F21.
13. Check your results with the Outcomes overleaf.
14. Close the document and say NO to save changes.
16
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
Outcome answers for exercise
17
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
Outcome with formulas: -
18
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
Odds & Ends
Paste special
Linking sheets through copy and paste:
If you copy your spreadsheet to another sheet or workbook. When you go to
paste onto the destination sheet use paste special. This acts as a link between
the two sheets. Ensure you click the Paste Link button. Now if you change any
data on the original source spreadsheet the linked sheet automatically updates.
Linking Cells
If you want to link the contents of two cells together. Select the destination cell
type =. Then using your mouse click on the cell with the data then press enter.
You can use this principle for linking cells from one sheet to another.
Freezing and Unfreezing Rows and Columns
When you have a large worksheet, it’s difficult to navigate around when you can
no longer see the row and column labels at the top and left of the worksheet.
Excel can help by freezing row and column labels so they stay put as you scroll to
see the rest of the data. This process is called freezing panes.
To freeze rows and columns click in the first cell of the worksheet you do not want
frozen. (Excel freezes everything above and to the left of a selected cell). Using
mouse click on Window > Freeze panes. Some bold lines should appear on your
worksheet identifying which cells have been frozen. See example below.
19
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
To unfreeze panes simply click on the Window menu and select unfreeze panes.
20
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
Protection/Unlocking cells
Within Excel you can protect certain cells so that the Data cannot be edited.
To do this first highlight the cells that you do not want to be protected. Then using
mouse go to Format > Cells > click on protection tab. Take the tick out of the
locked option then OK. See below for example:-
Then go to Tools > Protections > Protect sheet. See below for confirmation:-
You can password protect if you wish. If not leave the password field blank.
NB: If you password protect ensure someone else knows the password.
cannot help you if you lose of forget the password.
To unprotect the sheet go to the Tools > protection> unprotect option.
21
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
IT
Data Validation
You can set messages or instructions to display on your worksheet as people type
or can set criteria so that the cells only accept certain data.
Highlight the column or cells you wish to apply the instruction to:
Then click on the Data menu and highlight Validation. A dialogue box should
appear like the example below:- Within this box enter the criteria.
If you wish to have a message appear as well click the Input Message Tab and
type your message. Then Click OK to confirm.
22
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
Creating a drop down list
First select the cells or columns you wish to add a drop down list to. Then from
the menu bar click Data > Validation.
The data validation dialogue box will
appear. On the settings tab under validation criteria click on the drop down arrow
and choose List. Enter your list separated by commas. See example below:-
Select list from drop
down menu
Source data
selector button
Enter your list separated by
commas. Once complete
click OK
This condition has now been completed and each time you click on the cells a
drop down arrow should appear for people to select from.
NB: If you already have a list created on the same sheet instead of manually
typing in the list click on the selector button and highlight the range. Then click
back on the minimised selector button to click OK. You can also have the list on a
separate sheet within the same workbook. The source list needs to be selected
and the range needs naming. To name the range:Highlight range then in the Name box enter list name. Then you repeat steps
above on how to create a drop down list but in the source section type =name of
list.
Name box – select list
click in name box and
enter list name (no
space).
23
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
Custom Lists
If you are creating a spreadsheet where you want to keep repeating a group of
words such as a staff rota and staff names. You can create your own custom lists
to use with the auto fill feature.
Select Tools from the menu bar and highlight > options. A dialog box should
appear. Click the custom lists tab and highlight the word NEW LIST > Add your
list entries in the order you wish them to appear, Click Add then OK. See
example below:-
If you want to apply your new list to your spreadsheet, enter one of the names
from the list into a cell – then using auto fill drag across a range of cells.
NB: Note your names will auto fill in the order you have typed them.
24
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
Conditional Formatting
Conditional formatting allows the user to apply formats to selected cells based on
a condition. For example:- If you wanted to set a condition on your worksheet
stating that wherever a number is greater than (>) 50 you wish the font colour to
appear in Red.
Select the cells, rows or columns you wish to apply the condition to. Click on the
Format menu and select conditional formatting. A dialog box should appear,
working through the drop down menu’s set your condition.
If you want to change the appearance of the cell you need to click the Format
button. To confirm your condition press OK.
If you wish to apply a condition that formats a range of cells such as an entire row
dependant upon a criteria set within a cell, you need to enter a formula. For
example if you had a large worksheet containing patient details and you wanted to
alert yourself to patients of a certain age as new/old patients get entered.
First select the range of cells then click on Format > conditional formatting. In the
dialog box change the first drop down menu from Cell Value is to Formula is, then
enter the formula using $ signs to signify the cell that the criteria applies to. After
you have entered your formula click the format button to change the appearance
of your cell range. To confirm your condition press OK.
The example below shows that if cell D3 is greater than 10, then the whole of row
3 will be formatted to red text with yellow shading.
25
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
Consolidation exercise for Odds & Ends
1.
Open a new spreadsheet and on sheet 1create the following student
attendance table using the cell references as indicated in the table below.
2.
Add the appropriate formula in order to calculate the sum of cells B4 to B7
so that the answer appears in cell B8.
3.
Replicate this formula to add the totals for Maths and Science.
4.
Add the correct formula to calculate the average of the cell range B4 to D4
so that the answer appears in cell E4.
5.
Replicate the formula in cell E4 to cells E5, E6 and E7 to calculate the
average for October, November and December.
6.
Copy all the text and figures from sheet 1 and paste special onto sheet 2
starting at cell reference A1. Check that paste special has worked by
altering the figure in sheet 1 cell D5 from 23 to 40. Check that both tables
have been updated.
7.
Create a new Custom list for the subjects, English Maths and Science.
Check your list works by using the Auto fill facility starting in cell A1 : A3 on
Sheet 3. Remember you will need to enter one of the subjects before you
use auto fill.
8.
On sheet 1 Protect column E so it cannot be amended. (Do not use
password).
9.
On sheet 2 Select the cell range B4: D7. Apply Data Validation so that the
settings display whole numbers between 5 and 40, add an input message to
appear that says – Only enter numbers between 5 & 40.
10. On sheet 2 using the cell range B8:D8 apply conditional formatting so any
number less than 75 will be displayed in red font.
11. On sheet 3 Create a drop down list via data validation to appear on Column
B using the source data from A1:A3.
12. Ask the Tutor to check your work then close without saving changes.
26
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
Outcome for exercise
Sheet 1.
Sheet 2
Sheet 3
27
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc
Notes……
28
Formulas and Functions
April 09
C:\Documents and Settings\skoludek_r\Desktop\MSprogs\Excel\Formulas and Functions handout.doc