Professional Documents
Culture Documents
Provide Decision-Making Capability: Chapter 4: Introducing Worksheet Functions
Provide Decision-Making Capability: Chapter 4: Introducing Worksheet Functions
=IF(A1<100000,A1*5%,A1*7.5%)
The IF function takes three arguments, each separated by a comma. These arguments provide
input to the function. The formula is making a decision: If the value in cell A1 is less than 100,000,
then return the value in cell A1 multiplied by 5 percent. Otherwise, return the value in cell A1 mul-
tiplied by 7.5 percent.
If you’re ready to create your own custom functions by using VBA, check out Part VI of
this book.
The sheer number of available worksheet functions may overwhelm you, but you’ll probably find
that you use only a dozen or so of the functions on a regular basis. And as you’ll see, the Function
Library group on the Formulas tab (described later in this chapter) makes it easy to locate and
insert a function, even if you use it only rarely.
h No arguments
h One argument
h A fixed number of arguments
h An indeterminate number of arguments
h Optional arguments
For example, the RAND function, which returns a random number between 0 and 1, doesn’t use
an argument. Even if a function doesn’t require an argument, you must provide a set of empty
parentheses, like this:
=RAND()
If a function uses more than one argument, a comma separates the arguments. For example, the
LARGE function, which returns the nth largest value in a range, uses two arguments. The first
argument represents the range; the second argument represents the value for n. The formula
below returns the third-largest value in the range A1:A100:
=LARGE(A1:A100,3)
In some non-English versions of Excel, the character used to separate function argu-
ments can be something other than a comma — for example, a semicolon. The exam-
ples in this book use a comma as the argument separator character.
The examples at the beginning of the chapter use cell or range references for arguments. Excel
proves quite flexible when it comes to function arguments, however. The following sections dem-
onstrate additional argument types for functions.
Names as arguments
As you’ve seen, functions can use cell or range references for their arguments. When Excel calcu-
lates the formula, it simply uses the current contents of the cell or range to perform its calcula-
tions. The SUM function returns the sum of its argument(s). To calculate the sum of the values in
A1:A20, you can use
=SUM(A1:A20)
And, not surprisingly, if you’ve defined a name for A1:A20 (such as Sales), you can use the name
in place of the reference:
=SUM(Sales)
For more information about defining and using names, refer to Chapter 3.
=SUM(B:B)
Using full-column and full-row references is particularly useful if the range that you’re summing
changes — if you continually add new sales figures, for instance. If you do use an entire row or
column, just make sure that the row or column doesn’t contain extraneous information that you
don’t want to include in the sum.
You may think that using such a large range (a column consists of 1,048,576 cells) might slow
down calculation time. Not true. Excel keeps track of the last-used row and last-used column and
does not use cells beyond them when computing a formula result that references an entire col-
umn or row.
=SQRT(225)
Using a literal argument with a simple function like this one usually defeats the purpose of using
a formula. This formula always returns the same value, so you could just as easily replace it with
the value 15. You may want to make an exception to this rule in the interest of clarity. For exam-
ple, you may want to make it perfectly clear that you are computing the square root of 225.
Using literal arguments makes more sense with formulas that use more than one argument. For
example, the LEFT function (which takes two arguments) returns characters from the beginning
of its first argument; the second argument specifies the number of characters. If cell A1 contains
the text Budget, the following formula returns the first letter, or B:
=LEFT(A1,1)
Expressions as arguments
Excel also enables you to use expressions as arguments. Think of an expression as a formula
within a formula (but without the leading equal sign). When Excel encounters an expression as a
function’s argument, it evaluates the expression and then uses the result as the argument’s value.
Here’s an example:
=SQRT((A1^2)+(A2^2))
This formula uses the SQRT function, and its single argument appears as the following expression:
(A1^2)+(A2^2)
When Excel evaluates the formula, it first evaluates the expression in the argument and then
computes the square root of the result.
sometimes known as nesting functions. Excel starts by evaluating the most deeply nested
expression and works its way out. Note this example of a nested function:
=SIN(RADIANS(B9))
The RADIANS function converts degrees to radians, the unit used by all of the Excel trigonomet-
ric functions. If cell B9 contains an angle in degrees, the RADIANS function converts it to radians
and then the SIN function computes the sine of the angle.
A formula can contain up to 64 levels of nested functions — a limit that will probably never be a
factor.
Arrays as arguments
A function can also use an array as an argument. An array is a series of values separated by a
comma and enclosed in brackets. The formula below uses the OR function with an array as an
argument. The formula returns TRUE if cell A1 contains 1, 3, or 5.
=OR(A1={1,3,5})
See Part IV of this book for more information about working with arrays.
Often, using arrays can help simplify your formula. The formula below, for example, returns the
same result but uses nested IF functions instead of an array:
=IF(A1=1,TRUE,IF(A1=3,TRUE,IF(A1=5,TRUE,FALSE)))