Sunteți pe pagina 1din 7

Lecture No.

5: FORMULAS

The main use of a spreadsheet is to automate calculations, which means using cells to
perform operations based on values in other cells. The spreadsheet recalculates all the
values each time a change is made to the value of a cell.

A formula is used to represent an expression, which, one entered into the cell, allows the
spreadsheet to perform automatic calculations based on values in other cells and to
display the result.

Formulas may also contain references to other cells, expressions, or functions.

Formulas are equations using numbers and variables to get a result. In a spreadsheet, the
variables are cell locations that hold the data needed for the equation to be completed.

Creating formulas

You can enter formulas in two ways, either by using the Function Wizard, or by typing
directly into the cell or into the input line. A formula must begin with an = symbol, so when
typing in directly, you need to start a formula with one of the following symbols: =, + or .
Calc automatically adds the = symbol for the formula, when starting with the + or _
character. Starting with anything else causes the formula to be treated as if it were text.

Examples of formulas:

Add cells B4, C4, D4, and E4: =B4+C4+D4+E4


Subtract cell F10 from cell F9: =F9-F10
Multiply cells A3 and A4: =A3*A4
Divide cell D5 by cell D6 =D5/D6

Note: Always use cell references or cell address instead of values in your formulas! That
way, when the values change the formulas gets updated.

Explicit (literal) values and cell references

You can use both explicit values and cell references in a formula
An explicit value is also called a literal value
Formula with only cell references: =b3+b4
Formula with only literal values: =15+46
Formula with both cell references and literal values: =a1/100

1
Common ways to use formula and function

OPERATOR TYPES

Arithmetic operators

The addition, subtraction, multiplication and division operators return numerical results.
The Negation and Percent operators identify a characteristic of the number found in the
cell, for example -37. The example for Exponentiation illustrates how to enter a number
that is being multiplied by itself a certain number of times, for example 23 = 2*2*2.

2
Order of calculation

You can use several operations in one function. You can group those operations with
parentheses.
Examples
=3*2+1
=c1*(a1+b1)
=(100*a2-10)+(200*b3-20)+30
=(3+2*(50/b3+3)/7)*(3+b7)

Order of calculation refers to the sequence in which numerical operations are performed.
Division and multiplication are performed before addition or subtraction. There is a
common tendency to expect calculations to be made from left to right as the equation
would be read in English. Calc evaluates the entire formula, then based upon
programming precedence breaks the formula down executing multiplication and division
operations before other operations. Therefore, when creating formulas you should test
your formula to make sure that the correct result is being obtained.

Following is an example of the order of calculation in operation.

Example:
What is the value of the following expression?
=3 + (100 - 20) / 10 - 6 * 2 / 4 + 9

3
Comparative operators

Comparative operators return either a true or false answer. A direct answer of TRUE or
FALSE can be obtained by entering a formula such as =B6>B12. If the numbers found in
the referenced cells are accurately represented, the answer TRUE is returned, otherwise
FALSE is returned.

If cell A1 contains the numerical value 4 and cell B1 the numerical value 5, the above examples
would yield results of FALSE, FALSE, TRUE, FALSE, TRUE, and TRUE.

Text operators

It is common for users to place text in spreadsheets. To provide for variability in what and
how this type of data is displayed, text can be joined together in pieces coming from
different places on the spreadsheet.

In this example, specific pieces of the text were found in three different cells. To join these
segments together, the formula also adds required spaces and punctuation enclosed
within quotation marks, resulting in a formula of =B2 & " " & C2 & ", " & D2. The result is
the concatenation into a date formatted in a particular sequence.

Reference operators
An individual cell is identified by the column identifier (letter) located along the top of the
columns and a row identifier (number) found along the left-hand side of the spreadsheet.
On spreadsheets read from left to right, the reference for the upper left cell is A1.

4
Thus in its simplest form a reference refers to a single cell, but references can also refer
to a rectangle or cuboid range or a reference in a list of references. To build such
references you need reference operators.

The reference, A24:AMJ24, refers to all the cells in in row 24.


The reference, B1:B1048576, refers to all the cells in in column B.
The reference, B1:C1048576, refers to all the cells in in columns B and C.

Examples:

A1 this is a cell reference on the current sheet


A.A1 "A" is the name of sheet. "A1" is a cell on the "A" sheet
B1:B4 this is a range on the current sheet
B1.B4 "B1" is the name of a sheet. "B4" is a cell on the "B1" sheet

If a sheet name has a space in it, you must surround the sheet name with
apostrophes (i.e. single quotes)

'2002 Forecasts'.f3:f10
=sum('2002 Forecasts'.f3:f10)

Cell reference indicates a cells location and provides instructions for how cell data is
copied or used in calculations.
Relative (cell value changes as the formula is copied)
Absolute (cell value remains static when copied to other locations)
Mixed reference indicates the combination of an absolute cell and a
relative cell
Relative Reference vs. Absolute Reference vs. Mixed Reference
By default, when you copy a formula that contains a cell reference, excel will automatically
adjust the cell reference.
You can stop a spreadsheet from automatically adjusting the cell reference by using one
or more dollar signs ($) in the cell reference. These are called absolute cell references.
A cell reference without a dollar sign is a relative cell reference.
Example:
The following all refer to the same cell
d9
$d$9
$d9
d$9

5
The only difference between these cell references relates to what happens when you
copy a formula that contains the cell reference.
Relative Cell Reference
d9 This is a "relative cell reference".
Changing the column: If I copy this cell reference to another cell:
the "d" will increment one letter for every cell that I move over to the right.
the "d" will decrement one letter for every cell that I move over to the left

Changing the row: If I copy this cell reference to another cell:


the "9" will increment by one for every cell that I move down.
the "9" will decrement by one for every cell that I move up

Absolute Cell Reference


$d$9 This is an absolute cell reference.
If I copy a formula with this cell reference, the cell reference will NOT change AT ALL.
Mixed Cell References
$d9 and d$9 These are "Mixed" cell references:
$d9
The "d" will stay the same when you copy the cell, but the "9" will change.
d$9
The "d" will change when you copy the cell, but the "9" will stay the same.

Range operator

The range operator is written as a colon. An expression using the range operator has the
following syntax:

reference upper left : reference lower right

The range operator builds a reference to the smallest


range including both the cells referenced with the left
reference and the cells referenced with the right
reference.

6
Common Errors in Formula
The following are some errors that may appear in a spreadsheet (there are others
too).
#######
Cell is too narrow to display the results of the formula. To fix this
simply make the column wider and the real value will be displayed
instead of the ###### signs. Note that even when the ###### signs
are being displayed, Excel still uses the real value to calculate
formulas that reference this cell.
#NAME?
You used a cell reference in the formula that is not formed correctly
(e.g. =BB+10 instead of =B3+10)
#VALUE!
Usually the result of trying to do math with a textual value. Example:
=A1*3 where A1 contains the word hello
#DIV/0!
Trying to divide by zero. Example: =3/A1 where A1 contains 0 (zero)
Circular Reference
Using a formula that contains a reference to the cell that the formula
lives in. Example: putting the formula =A1+1 in cell A1 or putting
the formula =SUM(A1:B2) in any of the cells A1, B1, A2, B2

S-ar putea să vă placă și