Professional Documents
Culture Documents
Theresa A Scott, MS
Department of Biostatistics
Vanderbilt University
theresa.scott@vanderbilt.edu
This document contains a series of examples that illustrate some useful functions and formulas you
can use in Microsoft Excel. It is meant to be an extension of my Formulas & Functions in Microsoft
Excel lecture that is available on my website (http://boistat.mc.vanderbilt.edu/TheresaScott) under
Current Teaching Material.
General Instructions:
All of the demonstrated functions and formulas are calculated in a separate column from the
column(s) containing the cells they reference most often the directly adjacent column.
Depending on the layout of your spreadsheet, this may require you to insert a new column
between existing columns.
The functions and formulas are demonstrated in only a few rows. You will have to copy and
paste the function/formula down the appropriate column in your spreadsheet in order for it to
calculate the result for every desired row.
A help file, which includes examples, can be accessed for any function by clicking the Help on
this function link in the Function Wizard after youve highlighted the function of interest.
Functions to be illustrated (listed by category):
Date and Time:
TODAY; NOW: returns the current date, the current date and time, respectively.
DATE: returns the number that represents the date given in Excel date-time code.
TIME: converts the hours, minutes, and seconds given as numbers to an Excel serial
number (formatted with a time format).
DAY; MONTH; and YEAR: returns the day of the month (1 to 31), the month (1 to 12), and
year from a date, respectively.
HOUR; MINUTE; and SECOND: returns the hour (0 to 23), minute (0 to 59), and second (0
to 59) from a time, respectively.
Engineering:
CONVERT: converts a number (or a time) from one measurement system to another.
Information:
COUNTBLANK: counts the number of blank cells in a specified range of cells.
Logical:
AND: checks whether all of the arguments are TRUE and returns TRUE only if all
arguments are TRUE (returns FALSE otherwise).
OR: checks whether any of the arguments are TRUE and returns FALSE only if all
arguments are FALSE (returns TRUE otherwise).
IF: checks whether a condition is met, and returns one value if TRUE, another if FALSE.
Math:
COUNTIF: counts the number of cells within a range that meet the given condition.
ROUND, ROUNDDOWN, and ROUNDUP: rounds a number to a specified number of
digits, down (toward zero), and up (away from zero), respectively.
SUMIF: adds all the cells specified by a given condition, respectively.
Statistical:
COUNTA: counts the number of cells that are not empty.
Page 1
1 There is additionally an extensive amount of Financial functions available full list given in the Function Wizard.
Page 2
Name
2 nancy Davolio
Formula
Result
=UPPER(A2)
NANCY DAVOLIO
=LOWER(A2)
nancy davolio
Remove spaces from the beginning and end of a cell with the TRIM function.
Example spreadsheet:
A
1
2
3
Data
BD122
Vitamin A
Formula
Result*
=TRIM(A2) BD122
=TRIM(A3) Vitamin A
* original text strings were BD122
and
Vitamin A.
Remove characters from text using the LEFT, RIGHT, and LEN functions.*
Example spreadsheet:
A
1
Data
2 Vitamin Ester-C
3 Vitamin B1
Formula
=LEFT(A2, LEN(A2)-8)
Result
Vitamin
=RIGHT(A3, LEN(A3)-8) B1
* Depending on the situation, can also use the Replace from the Edit drop-menu.
Page 3
Davolio
3 Andrew
Fuller
Formula
Result
=A2& B2
Nancy Davolio
=B3&, A3
Fuller, Andrew
Extract the first or last name from a cell containing both first and last name using the LEFT,
RIGHT, and SEARCH functions.
Example spreadsheet:
A
1
Name
2 Nancy Davolio
3 Fuller, Andrew
Formula
Result
Nancy
Davolio
Fuller
Andrew
Common Math:
Convert measurements using the CONVERT function (see help file for complete list).
Example spreadsheet:
A
1
Data
2 6
Formula
Result
=CONVERT(A2, C, F)
42.8
Page 4
2.362204724
Data
2 20.3
3 -5.9
4 12.5493
5 22230
Formula
Result
=ROUND(A2, 0)
20
=ROUNDUP(A2, 0)
21
=ROUNDUP(A4, 2)
12.55
=ROUNDDOWN(A3, 0)
-5
=ROUNDDOWN(A4, 2)
12.54
=ROUND(A5, -2)
22200
=ROUNDUP(A5, -3)
23000
NOTE: Use the Number tab from the Format Cells dialog box (reached via Cells from
the Format drop-menu) to only change the number of decimal places displayed
(ie, this does not change the actual number).
Data
2 20.3
3
4 12.5
5 15.0
Formula
Result
=COUNTA(A2:A5)
=COUNTBLANK(A2:A5)
NOTE: PivotTables are an alternative to manually calculating counts using function and
formulas see my PivotTable & PivotChart Reports, and Macros in Microsoft Excel
lecture (also available on my website).
Page 5
15000
3 Buchanan
9000
4 Suyama
8000
5 Suyama
20000
6 Buchanan
5000
7 Dodsworth
22500
Formula
Result
=COUNTIF(B2:B7, >9000)
=COUNTIF(B2:B7, <=9000)
=COUNTIF(A2:A7, Buchanan) 3
=COUNTIF(A2:A7, A4)
15000
3 Buchanan
9000
4 Suyama
8000
5 Suyama
20000
6 Buchanan
5000
7 Dodsworth
22500
Formula
Result
29000
66500
13000
NOTE: The three arguments to the SUMIF function are (1) the range to evaluate (these
cells are checked to determine whether a row meets the criteria); (2) the criteria (the
condition that the cells evaluated must meet for the row to be included in the sum); and
(3) the range to sum (the numbers in these cells are added, provided the row satisfies
the condition).
Page 6
Common Conditional:
Conditionally evaluate the contents of a cell using the IF, AND, and OR functions:
Example spreadsheet:
A
B
1
Gender
Test Value
2 Female
15
3 Male
4 Female
5 Female
20
6 Male
7 Male
22
Formula
Result
High Risk
Result
=TODAY()
=NOW()
Time
2 6
3 10:35 AM
4 12.25
Page 7
Formula
Result
144
360
2191.5
=(A3-INT(A3))*24
10.583333
=TEXT(A4/24, h:mm)
12:15
NOTE: The fourth and fifth formulas convert hours from a standard format (hours :
minutes : seconds) to a decimal number and vice versa (reference time = 12:00 AM).
Add dates.
Example spreadsheet:
A
Days to add
Months to add
Years to add
2 6/9/2007
3 9/2/2007
4 12/10/2008
25
Date
Formula
Result
=A2+B2
6/12/2007
=A4+B4
2/2/2009
9/9/2007
2/2/2008
12/10/2010
9/12/2010
Add times.
Example spreadsheet:
1
Time
Time to be added
2 10:35:00 AM
10
Formula
Result
=A2 + TIME(B2, 0, 0)
08:35:00 PM
10:45:00 AM
10:35:10 AM
Page 8
Date1
B
Date2
2 6/9/2007
6/15/2007
3 9/2/2007
10/8/2007
4 12/10/2008
9/19/2009
Formula
Result
=A3 A2
=MONTH(B3) MONTH(B2)
=YEAR(B4) YEAR(A4)
Start time
2 6/9/2007 10:35 AM
End time 1
6/9/2007 3:30 PM
Formula
C
End time 2
6/10/2007 4:30 PM
Result
=TEXT(B2-A2, h)
=TEXT(B2-A2, h:mm)
4:55
=TEXT(B2-A2, h:mm:ss)
4:55:00
=INT((C2-A2)*24)
29
Page 9