Ormulas and Functions
Ormulas and Functions
Enter a Formula | Edit a Formula | Operator Precedence | Copy/Paste a Formula | Insert a Function
A formula is an expression which calculates the value of a cell. Functions are predefined formulas and are already
available in Excel.
For example, cell A3 below contains a formula which adds the value of cell A2 to the value of cell A1.
For example, cell A3 below contains the SUM function which calculates the sum of the range A1:A2.
Enter a Formula
To enter a formula, execute the following steps.
1. Select a cell.
2. To let Excel know that you want to enter a formula, type an equal sign (=).
3. For example, type the formula A1+A2.
Tip: instead of typing A1 and A2, simply select cell A1 and cell A2.
4. Change the value of cell A1 to 3.
Excel automatically recalculates the value of cell A3. This is one of Excel's most powerful features!
Edit a Formula
When you select a cell, Excel shows the value or formula of the cell in the formula bar.
1. To edit a formula, click in the formula bar and change the formula.
2. Press Enter.
Operator Precedence
Excel uses a default order in which calculations occur. If a part of the formula is in parentheses, that part will be
calculated first. It then performs multiplication or division calculations. Once this is complete, Excel will add and
subtract the remainder of your formula. See the example below.
First, Excel performs multiplication (A1 * A2). Next, Excel adds the value of cell A3 to this result.
Another example,
First, Excel calculates the part in parentheses (A2+A3). Next, it multiplies this result by the value of cell A1.
Copy/Paste a Formula
When you copy a formula, Excel automatically adjusts the cell references for each new cell the formula is copied to.
To understand this, execute the following steps.
1. Enter the formula shown below into cell A4.
2a. Select cell A4, right click, and then click Copy (or press CTRL + c)...
...next, select cell B4, right click, and then click Paste under 'Paste Options:' (or press CTRL + v).
2b. You can also drag the formula to cell B4. Select cell A4, click on the lower right corner of cell A4 and drag it across
to cell B4. This is much easier and gives the exact same result!
Insert a Function
Every function has the same structure. For example, SUM(A1:A4). The name of this function is SUM. The part
between the brackets (arguments) means we give Excel the range A1:A4 as input. This function adds the values in
cells A1, A2, A3 and A4. It's not easy to remember which function and which arguments to use for each task.
Fortunately, the Insert Function feature in Excel helps you with this.
To insert a function, execute the following steps.
1. Select a cell.
4. Click OK.
The 'Function Arguments' dialog box appears.
5. Click in the Range box and select the range A1:C2.
6. Click in the Criteria box and type >5.
7. Click OK.
Result. Excel counts the number of cells that are higher than 5.
Note: instead of using the Insert Function feature, simply type =COUNTIF(A1:C2,">5"). When you arrive at:
=COUNTIF( instead of typing A1:C2, simply select the range A1:C2.
https://exceljet.net/formulas
https://exceljet.net/formula/count-unique-numeric-values-in-a-range
Arithmetic operators
To perform basic mathematical operations such as addition,
subtraction, or multiplication; combine numbers; and produce
numeric results, use the following arithmetic operators.
Arithmetic operator
Meaning
Example
+ (plus sign)
Addition
3+3
(minus sign)
Subtraction
31
Arithmetic operator
Meaning
Example
Negation
* (asterisk)
Multiplication
3*3
/ (forward slash)
Division
3/3
% (percent sign)
Percent
20%
^ (caret)
Exponentiation)
3^2
Comparison operators
You can compare two values with the following operators. When
two values are compared by using these oper
Comparison operator
Meaning
Example
= (equal sign)
Equal to
A1=B1
Greater than
A1>B1
Less than
A1<B1
A1>=B1
A1<=B1
Not equal to
A1<>B1
Meaning
Example
&
(ampersand)
"North"&"wind"
Reference operators
Combine ranges of cells for calculations with the following
operators.
Reference
operator
Meaning
Example
: (colon)
, (comma)
(space)
SUM(B5:B15,D5:D15)
Description
: (colon)
Reference operators
(single space)
, (comma)
Operator
Description
Negation (as in 1)
Percent
Exponentiation
* and /
+ and
&
=
<>
<=
>=
<>
Comparison
Use of parentheses
To change the order of evaluation, enclose in parentheses the part of
the formula to be calculated first. For example, the following
formula produces 11 because Excel calculates multiplication before
addition. The formula multiplies 2 by 3 and then adds 5 to the result.
=5+2*3
In contrast, if you use parentheses to change the syntax, Excel adds
5 and 2 together and then multiplies the result by 3 to produce 21.
=(5+2)*3
In the example below, the parentheses around the first part of the
formula force Excel to calculate B4+25 first and then divide the
result by the sum of the values in cells D5, E5, and F5.
=(B4+25)/SUM(D5:F5)
Top of Page
Structure of a function
1. Structure. The structure of a function begins with an equal sign
(=), followed by the function name, an opening parenthesis, the
arguments for the function separated by commas, and a closing
parenthesis.
Entering functions
When you create a formula that contains a function, the Insert
Function dialog box helps you enter worksheet functions. As you
enter a function into the formula, the Insert Function dialog box
displays the name of the function, each of its arguments, a
description of the function and each argument, the current result of
the function, and the current result of the entire formula.
To make it easier to create and edit formulas and minimize typing
and syntax errors, use formula autocomplete. After you type an =
(equal sign) and beginning letters or a display trigger, Microsoft
Office Excel displays below the cell a dynamic drop down list of
valid functions, arguments, and names that match the letters or
trigger. You can then insert an item in the drop-down list into the
formula.
Nesting functions
In certain cases, you may need to use a function as one of the
arguments of another function. For example, the following formula
uses a nested AVERAGE function and compares the result with the
value 50.
Use
A10
A10:A20
B15:E15
5:5
5:10
H:H
H:J
R[2]C[2]
A relative reference to the cell two rows down and two columns
to the right
R2C2
R[-1]
Reference Meaning
R
Referen =SUM(C20:C30)
ce
=SUM(FirstQuarterSales)
Constan =PRODUCT(A5,8.3)
t
=PRODUCT(Price,WASales
Tax)
Formula =SUM(VLOOKUP(A1,B1:F20,5,F
ALSE), G5)
=SUM(Inventory_Level,
Order_Amt)
Table
=TopSales06
C4:G36
Types of names
There are several types of names you can create and use.
Defined name A name that represents a cell, range of cells,
formula, or constant value. You can create your own defined name,
and Excel sometimes creates a defined name for you, such as when
you set a print area.
Table name A name for an Excel table, which is a collection of
data about a particular subject that is stored in records (rows) and
fields (columns). Excel creates a default Excel table name of
"Table1", "Table2", and so on, each time you insert an Excel table,
but you can change the name to make it more meaningful. For more
information on Excel tables, see Using structured references with
Excel tables.
Name box on the formula bar This is best used for creating
a workbook level name for a selected range.
New Name dialog box This is best used for when you want
more flexibility in creating names, such as specifying a local
worksheet level scope or creating a name comment.
NOTE: By default, names use absolute cell references.
Typing
formula.
Select a
To understand how to write formulas and functions, you need to know about rows and columns.
Rows run horizontally and columns run vertically. To remember which is which, think of a column
holding up a roof columns go up-down and thus rows go left-right.
Columns are labeled by letters; rows by numbers. The first cell in the spreadsheet is A1
meaning column A, row 1. The columns are labeled A-Z. When the alphabet runs outs, Excel
places another letter in front: AA, AB, AC AZ, BA, BC, BC, etc.
Example: Function Sum()
Now lets demonstrate how to use a function.
You use functions by typing them directly in or using the function wizard. The function wizard
opens when you either pick a function from the Formulas menu from the Function Library.
Otherwise, you can type = in a cell and a handy drop-down menu will allow you to pick a
function.
The wizard tells you what arguments you need to provide for each function. It also provides a
link to online instructions if you need help understanding what the function does and how to use
it. For example, if you type =sum into a cell, the in-line wizard shows you what arguments are
required for the SUM function.
When you type a function, the wizard is inline or right at your fingers. When you select a
function from the Formulas menu, the wizard is a pop-up box. Here is the pop-up wizard for
the SUM() function.
For our first function, lets use SUM(), which adds a list of numbers.
Suppose we have this spreadsheet to contain plans for budgeting your familys vacation:
To calculate the total costs you could write =b2+b3+b4+b5 but its easier to use the SUM()
function.
In Excel, look for the symbol at the top left-hand corner of the Excel screen to find the
AutoSum button (mathematicians use the Greek letter for adding a series of numbers).
If the cursor is below the family budget numbers, Excel is smart enough to know that you want
to sum the list of numbers above where you placed the cursor, so it highlights the numbers.
Press enter to accept the range selected by Excel or use the cursor to change which cells are
selected.
If you look at what Excel put into the spreadsheet you can see that it wrote this function:
In this formula, Excel sums the numbers from B2 to B9. Note, we left some room below row 5 so
that you could add to the family vacation budget the cost will certainly go up as the kids list of
what they want to do and where they want to go grows longer!
Math functions do not work with letters, so if you put letters into the column the result is shown
as #NAME? as shown below.
#NAME? indicates that there is some kind of error. It could be any number of things including:
The easiest way to select the arguments in a calculation is to use the mouse. You can add to or
remove from the list of arguments to the function by enlarging or making smaller the box that
Excel draws when you move the mouse or click in another cell.
We have clicked on the top of the square drawn by Excel to take airline tickets out of the
budget. You can see the cross-hair symbol that you can draw to make the selected range larger
or smaller.
Definition
addition
multiplication
division
percent
There are other operators not related to mathematics like & which means concatenate (join
end-to-end) two strings. For example, =Excel & is Fun equals Excel is Fun.
Now we look at comparison operators.
Compariso
n Operator
Definition
>
<
>=
<=
<>
As you can see above, comparison operators work with numbers and text.
Note, if you enter =a>b into a cell it will say FALSE since a is not greater than b. b
comes after a in the alphabet, so a > b or b > a.
Operator Order Precedence
Order precedence is an idea from mathematics. Excel has to follow the same rules as
mathematics. This topic is more complicated, so take a breath and lets dive in.
Order precedence means the order in which the computer calculates the answer. As we
explained in Lesson 1, the area of a circle is r2, which is the same as * r * r. It is not (r)2.
So you have to understand the order precedence when you write a formula.
Generally, you can say this:
1.
2.
3.
When two items have the same precedence, Excel works left to right.
( and )
* and /
Multiply and divide. How can two operators have the same
precedence? It just means that if a formula has two more operators
with the same precedence, then the calculation is done left to right.
+ and
There are other precedence rules related to strings and reference operators. For the moment,
we will just stick with what we just covered. Now, lets look at some examples.
Example: Calculating the area of a circle
The area of a circle is =PI() * radius ^ 2.
Looking at the table above we see that exponents comes before multiplication. So the computer
first calculates radius ^ 2 and then it multiples that result by Pi.
Example: Calculating a raise in salary
Lets say your boss decides youre doing a great job and he or she is going to give you a 10%
raise! How would you calculate your new salary?
First, remember that multiplication comes before addition.
Is it =salary + salary * 10% or is it =salary + (salary * 10%)?
Suppose your salary is $100. With a 10% raise, your new salary will be:
= 100 + 100 * 10% = 100 + 10 = 110
You can also write it like this:
Format the numbers with dollar signs and use zero decimal places since we are not interested
in cents right now because they do not matter much when you are talking about dollars (in the
next chapter we explore how to format numbers in detail). For example, to format the interest
rate, right-click on the cell and click format cells. Pick percentage and use 2 decimal places.
Similarly, format the other cells for currency instead of percentage and pick number for the
loan term.
Now we have:
Note, the mortgage cell is not included in the total. Excel does not know that you want to include
that number, since there is no value there. So be careful to extend the SUM() function to the top
either by using the cursor or typing E2 where it says E3 to include the mortgage in the sum.
Put the cursor in the payment cell (B4).
On the Formulas menu select the drop-down Financial and then select the PMT function. The
wizard pops up:
Use the cursor to select the rate.,nper (loan term), Pv (present value or loan amount).
Notice that you have to divide the interest rate by 12 since interest is calculated monthly. Also
you need to multiply the loan term in years by 12 to get the loan term in months. Press OK to
save the result in the spreadsheet.
Notice that the payment is shown as a negative number: -1013.37062. To make it positive and
add it to the monthly expenses, point to the mortgage cell (E2). Type =- then use the cursor to
point to the payment field. The resulting formula is =-B4.
To tackle this problem you need to use an algorithm i.e., a step-by-step procedure for doing
this.
For example, look at Washington, George. The procedure to split that into two words would be:
1.
2.
Find the position of the comma (this shows where one word ends and the other begins).
3.
4.
Copy the right-hand side of the string from the comma to the end.
Calculate the length of the string with the function =LEN(A3) the result is 18.
2.
Now find the position of the comma by entering this function =FIND(,,A3) the result
is 11.
3.
Now take the left-hand side of the string up until the comma and create this nested
formula using the result from Step 1: =LEFT(A3,FIND(,,A3)-1). Note, we have to subtract
1 from the length because FIND gives the position of the comma.
Here is what that all looks like when all the functions are placed together in a formula. In cell B3,
you can see this formula takes all the information from cell A3 and inputs Washington into it.
2.
3.
Count the characters from the end of the string to the comma.
Take the number of characters from Step 3 and subtract one to omit the comma and space.
Lets do this step-by-step.
1.
2.
3.
4.
You will need to use some math to find the number of characters to take: =LEN(A3)
FIND(,,A3) 1
The right-hand side of the string we want is =RIGHT(A3,LEN(A3) FIND(,,A3) 1)
Your spreadsheet should now look similar to the screenshot below. We copied the formulas as
text into the bottom of the spreadsheet to make it easier to read and see.
That one was a little difficult but you only need to write these formulas once.