Vous êtes sur la page 1sur 5

Chapter 4: Introducing Worksheet Functions 105

3. Activate cell A1 and choose Home➜Clipboard➜Paste➜Paste Values to convert the for-


mulas to values.
4. Delete column B.
You’re finished! With the help of a function, you just eliminated several hours of tedious
work in less than a minute.

Provide decision-making capability


You can use the Excel IF function to give your formulas decision-making capabilities. Suppose
that you have a worksheet that calculates sales commissions. If a salesperson sells at least
$100,000 of product, the commission rate reaches 7.5 percent; otherwise, the commission rate
remains at 5.0 percent. Without using a function, you would need to create two different formu-
las and make sure that you use the correct formula for each sales amount. This formula uses the
IF function to check the value in cell A1 and make the appropriate commission calculation:

=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.

More about functions


All told, Excel includes more than 400 functions. And if that’s not enough, you can purchase
additional specialized functions from third-party suppliers, and you can even create your own
custom functions (using VBA).

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.

Appendix A contains a complete listing of Excel’s worksheet functions, with a brief


description of each.

09_475362-ch04.indd 105 4/14/10 9:33 PM


106 Part II: Using Functions in Your Formulas

Function Argument Types


If you examine the preceding examples in this chapter, you’ll notice that all the functions use a
set of parentheses. The information within the parentheses is the function’s arguments. Functions
vary in how they use arguments. A function may use

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)

09_475362-ch04.indd 106 4/14/10 9:33 PM


Chapter 4: Introducing Worksheet Functions 107

Accommodating former Lotus 1-2-3 users


If you’ve ever used any of the Lotus 1-2-3 spreadsheets (or any version of Corel’s Quattro Pro),
you may recall that these products require you to type an “at” sign (@) before a function name.
Excel is smart enough to distinguish functions without you having to flag them with a symbol.
Because old habits die hard, however, Excel accepts @ symbols when you type functions in your
formulas, but it removes them as soon as you enter the formula.
These competing products also use two dots (..) as a range reference operator — for example,
A1..A10. Excel also enables you to use this notation when you type formulas, but Excel replaces
the notation with its own range reference operator, a colon (:).
This accommodation goes only so far, however. Excel still insists that you use the standard Excel
function names, and it doesn’t recognize or translate the function names used in other spread-
sheets. For example, if you enter the 1-2-3 @AVG function, Excel flags it as an error. (Excel’s
name for this function is AVERAGE.)

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.

Full-column or full-row as arguments


In some cases, you may find it useful to use an entire column or row as an argument. For exam-
ple, the following formula sums all values in column B:

=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.

09_475362-ch04.indd 107 4/14/10 9:33 PM


108 Part II: Using Functions in Your Formulas

Literal values as arguments


A literal argument refers to a value or text string that you enter directly. For example, the SQRT
function, which calculates the square root of a number, takes one argument. In the following
example, the formula uses a literal value for the function’s argument:

=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.

Other functions as arguments


Because Excel can evaluate expressions as arguments, it shouldn’t surprise you that these
expressions can include other functions. Writing formulas that have functions within functions is

09_475362-ch04.indd 108 4/14/10 9:33 PM


Chapter 4: Introducing Worksheet Functions 109

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)))

Ways to Enter a Function into a Formula


You can enter a function into a formula by typing it manually, by using the Function Library com-
mands, or by using the Insert Function dialog box.

Entering a function manually


If you’re familiar with a particular function — you know its correct spelling and the types of argu-
ments that it takes — you may choose to simply type the function and its arguments into your
formula. Often, this method is the most efficient.

09_475362-ch04.indd 109 4/14/10 9:33 PM

Vous aimerez peut-être aussi