Create or delete a formula

Formulas (formula: A sequence of values, cell references, names, functions, or operators in a cell that together produce a new value. A formula always begins with an equal sign (=).) are equations that perform calculations on values in your worksheet. A formula always starts with an equal sign (=).

You can create a simple formula by using constants (constant: A value that is not calculated. For example, the number 210 and the text "Quarterly Earnings" are constants. An expression, or a value resulting from an expression, is not a constant.) and calculation operators (operator: A sign or symbol that specifies the type of calculation to perform within an expression. There are mathematical, comparison, logical, and reference operators.). For example, the formula =5+2*3 multiplies two numbers and then adds a number to the result. Microsoft Office Excel follows the standard order of mathematical operations. In the preceding example, the multiplication operation (2*3) is performed first, and then 5 is added to its result.

You can also create a formula by using a function (function: A prewritten formula that takes a value or values, performs an operation, and returns a value or values. Use functions to simplify and shorten formulas on a worksheet, especially those that perform lengthy or complex calculations.). For example, the formulas =SUM(A1:A2) and SUM(A1,A2) both use the SUM function to add the values in cells A1 and A2.

Depending on the type of formula that you create, a formula can contain any or all of the following parts.


Parts of a formula

Callout 1 Functions A function, such as PI(), starts with an equal sign (=). For many functions, such as SUM(), you can enter arguments (argument: The values that a function uses to perform operations or calculations. The type of argument a function uses is specific to the function. Common arguments that are used within functions include numbers, text, cell references, and names.) within its parentheses. Each function has a specific argument syntax. Some arguments require exactly one argument, others require or allow several arguments (that is, some arguments might be optional), and some other functions allow no arguments at all — such as PI().
Callout 2 Cell references You can refer to data in worksheet cells by including cell references in the formula. For example, the cell reference A2 returns the value of that cell or uses that value in the calculation.
Callout 3 Constants You can also enter constants, such as numbers (such as 2) or text values, directly into a formula.
Callout 4 Operators Operators are the symbols that are used to specify the type of calculation that you want the formula to perform. For example, the ^ (caret) operator raises a number to a power, and the * (asterisk) operator multiplies numbers.

To achieve the calculation result that you want, you can use a single function, nested functions, or arrays (array: Used to build single formulas that produce multiple results or that operate on a group of arguments that are arranged in rows and columns. An array range shares a common formula; an array constant is a group of constants used as an argument.) that calculate single or multiple results.

What do you want to do?


Create a simple formula by using constants and calculation operators

  1. Click the cell in which you want to enter the formula.
  2. Type = (equal sign).
  3. To enter the formula, do one of the following:
    • Type the constants and operators that you want to use in the calculation.
Example formula What it does
=5+2 Adds 5 and 2
=5-2 Subtracts 2 from 5
=5/2 Divides 5 by 2
=5*2 Multiplies 5 times 2
=5^2 Raises 5 to the 2nd power
  • Click the cell that contains the value that you want to use in the formula, type the operator that you want to use, and then click another cell that contains a value.
Example formula What it does
=A1+A2 Adds the values in cells A1 and A2
=A1-A2 Subtracts the value in cell A2 from the value in A1
=A1/A2 Divides the value in cell A1 by the value in A2
=A1*A2 Multiplies the value in cell A1 times the value in A2
=A1^A2 Raises the value in cell A1 to the exponential value specified in A2

 Tip   You can enter as many constants and operators in a formula as you need, up to 8192 characters, to achieve the calculation result that you want.

  1. Press ENTER.

Top of Page Top of Page

Create a formula by using cell references and names

The example formulas at the end of this section contain relative references (relative reference: In a formula, the address of a cell based on the relative position of the cell that contains the formula and the cell referred to. If you copy the formula, the reference automatically adjusts. A relative reference takes the form A1.) to and names (name: A word or string of characters that represents a cell, range of cells, formula, or constant value. Use easy-to-understand names, such as Products, to refer to hard to understand ranges, such as Sales!C20:C30.) of other cells. The cell that contains the formula is known as a dependent cell when its value depends on the values in other cells. For example, cell B2 is a dependent cell if it contains the formula =C2.

  1. Click the cell in which you want to enter the formula.
  2. In the formula bar (formula bar: A bar at the top of the Excel window that you use to enter or edit values or formulas in cells or charts. Displays the constant value or formula stored in the active cell.) Button image, type = (equal sign).
  3. Do one of the following:
    • To create a reference, select a cell, a range of cells, a location in another worksheet, or a location in another workbook. This behavior is called semi-selection. You can drag the border of the cell selection to move the selection, or drag the corner of the border to expand the selection.

Range Finder color-codes precedent cells

Callout 1 The first cell reference is B3, the color is blue, and the cell range has a blue border with square corners.
Callout 2 The second cell reference is C3, the color is green, and the cell range has a green border with square corners.

 Note   If there is no square corner on a color-coded border, the reference is to a named range.

  • To enter a reference to a named range, press F3, select the name in the Paste name box, and click OK.
Example formula What it does
=C2 Uses the value in the cell C2
=Sheet2!B2 Uses the value in cell B2 on Sheet2
=Asset-Liability Subtracts the value in a cell named Liability from the value in a cell named Asset
  1. Press ENTER.

For more information, see Create or change a cell reference.

Top of Page Top of Page

Create a formula by using a function

  1. Click the cell in which you want to enter the formula.
  2. To start the formula with the function, click Insert Function Button image on the formula bar Button image.

Excel inserts the equal sign (=) for you.

  1. Select the function that you want to use.

If you're not sure which function to use, you can type a question that describes what you want to do in the Search for a function box (for example, "add numbers" returns the SUM function), or browse from the categories in the Or Select a category box.

 Tip   For a list of available functions, see List of worksheet functions (alphabetical) or List of worksheet functions (by category).

  1. Enter the arguments.

 Tip   To enter cell references as an argument, click Collapse Dialog Button image (which temporarily hides the dialog box), select the cells on the worksheet, and then press Expand Dialog Button image.

Example formula What it does
=SUM(A:A) Adds all numbers in column A
=AVERAGE(A1:B4) Averages all numbers in the range
  1. After you complete the formula, press ENTER.

 Tip   To summarize values quickly, you can also use AutoSum. On the Home tab, in the Editing group, click AutoSum, and then click the function that you want.

Top of Page Top of Page

Create a formula by using nested functions

Nested functions use a function as one of the arguments of another function. You can nest up to 64 levels of functions. The following formula sums a set of numbers (G2:G5) only if the average of another set of numbers (F2:F5) is greater than 50. Otherwise, it returns 0.


Nested functions

Callout 1 The AVERAGE and SUM functions are nested within the IF function.

  1. Click the cell in which you want to enter the formula.
  2. To start the formula with the function, click Insert Function Button image on the formula bar Button image.

Excel inserts the equal sign (=) for you.

  1. Select the function that you want to use.

If you're not sure which function to use, you can type a question that describes what you want to do in the Search for a function box (for example, "add numbers" returns the SUM function), or browse from the categories in the Or Select a category box.

 Tip   For a list of available functions, see List of worksheet functions (alphabetical) or List of worksheet functions (by category).

  1. To enter the arguments, do one or more of the following:
    • To enter cell references as an argument, click Collapse Dialog Button image next to the argument you want (which temporarily hides the dialog box), select the cells on the worksheet, and then press Expand Dialog Button image.
    • To enter another function as an argument, enter the function in the argument box that you want. For example, you can add SUM(G2:G5) in the Value_if_true edit box of the IF function.
    • The parts of the formula displayed in the Function Arguments dialog box reflect the function that you selected in the previous step. For example, if you clicked IF, the Function arguments dialog box displays the arguments for the IF function.

Top of Page Top of Page

Create an array formula that calculates a single result

You can use an array formula (array formula: A formula that performs multiple calculations on one or more sets of values, and then returns either a single result or multiple results. Array formulas are enclosed between braces { } and are entered by pressing CTRL+SHIFT+ENTER.) to perform several calculations to generate a single result. This type of array formula can simplify a worksheet model by replacing several different formulas with a single array formula.

  1. Click the cell in which you want to enter the array formula.
  2. Enter the formula that you want to use.

 Tip   Array formulas use standard formula syntax. They all begin with an equal sign, and you can use any of the built-in Excel functions in your array formulas.

For example, the following formula calculates the total value of an array of stock prices and shares, without using a row of cells to calculate and display the total values for each stock.

Array formula that produces a single result

Array formula that produces a single result

When you enter the formula {=SUM(B2:C2*B3:C3)} as an array formula, Excel multiples the number of shares by the price for each stock (500*10 and 300*15), and then adds the results of those calculations together to get a total value of 9500.

  1. Press CTRL+SHIFT+ENTER.

Excel automatically inserts the formula between { } (a pair of opening and closing braces).

 Note   Manually typing braces around a formula will not convert it into an array formula — you must press CTRL+SHIFT+ENTER to create an array formula.

 Important   Any time you edit the array formula, the braces ({ }) disappear from the array formula, and you must press CTRL+SHIFT+ENTER again to incorporate the changes into an array formula and to add the braces.

Top of Page Top of Page

Create an array formula that calculates multiple results

Some worksheet functions return arrays of values, or require an array of values as an argument. To calculate multiple results by using an array formula, you must enter the array into a range of cells that has the same number of rows and columns as the array arguments have.

  1. Select the range of cells in which you want to enter the array formula.
  2. Enter the formula that you want to use.

 Tip   Array formulas use standard formula syntax. They all begin with an equal sign, and you can use any of the built-in Excel functions in your array formulas.

For example, given a series of three sales figures (column B) for a series of three months (column A), the TREND function determines the straight-line values for the sales figures. To display all the results of the formula, it is entered into three cells in column C (C1:C3).

Array formula that produces multiple results

Array formula that produces multiple results

When you enter the formula =TREND(B1:B3,A1:A3) as an array formula, it produces three separate results (22196, 17079, and 11962), based on the three sales figures and the three months.

  1. Press CTRL+SHIFT+ENTER.

Excel automatically inserts the formula between { } (a pair of opening and closing braces).

 Note   Manually typing braces around a formula will not convert it into an array formula — you must press CTRL+SHIFT+ENTER to create an array formula.

 Important   Any time you edit the array formula, the braces ({ }) disappear from the array formula, and you must press CTRL+SHIFT+ENTER again to incorporate the changes into an array formula and to add the braces.

Top of Page Top of Page

Delete a formula

When you delete a formula, the resulting values of the formula is also deleted. However, you can instead remove the formula only and leave the resulting value of the formula displayed in the cell.

  • To delete formulas along with their resulting values, do the following:
    1. Select the cell or range of cells that contains the formula.
    2. Press DELETE.
  • To delete formulas without removing their resulting values, do the following:
  1. Select the cell or range of cells that contains the formula.

If the formula is an array formula, select the range of cells that contains the array formula.

ShowHow to select a range of cells that contains the array formula

  1. Click a cell in the array formula.
  2. On the Home tab, in the Editing group, click Find & Select, and then click Go To.
  1. Click Special.
  2. Click Current array.
  1. On the Home tab, in the Clipboard group, click Copy Button image.
    Copy command in the Clipboard group

    Keyboard shortcut    You can also press CTRL+C.
  2. On the Home tab, in the Clipboard group, click the arrow below Paste Button image, and then click Paste Values.

Top of Page Top of Page

Learn tips and tricks about creating formulas

Easily change the type of reference    To switch between relative, absolute, and mixed references:

  1. Select the cell that contains the formula.
  2. In the formula bar (formula bar: A bar at the top of the Excel window that you use to enter or edit values or formulas in cells or charts. Displays the constant value or formula stored in the active cell.) Button image, select the reference that you want to change.
  3. Press F4 to switch between the reference types.

Quickly copy formulas    You can quickly enter the same formula into a range of cells. Select the range that you want to calculate, type the formula, and then press CTRL+ENTER. For example, if you type =SUM(A1:B1) in range C1:C5, and then press CTRL+ENTER, Excel enters the formula in each cell of the range, using A1 as a relative reference.

Use Formula Autocomplete    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 (the beginning letters act as a display trigger), Excel displays a dynamic list of valid functions and names below the cell. After you insert the function or name into the formula by using an insert trigger (pressing TAB or double-clicking the item in the list), Excel displays any appropriate arguments. As you fill out the formula, typing a comma can also act as a display trigger — Excel may display additional arguments. You can insert additional functions or names into your formula and, as you type their beginning letters, Excel again displays a dynamic list from which you can choose.

Use Function ScreenTips    If you are familiar with the arguments of a function, you can use the function ScreenTip that appears after you type the function name and an opening parenthesis. Click the function name to view the Help topic on the function, or click an argument name to select the corresponding argument in your formula.

Top of Page Top of Page

Avoid common errors when creating formulas

The following table summarizes some of the the most common errors that you can make when entering a formula and how to correct those errors:

Make sure that you… More information
Match all open and close parentheses     Make sure that all parentheses are part of a matching pair. When you create a formula, Excel displays parentheses in color as they are entered.
Use a colon to indicate a range     When you refer to a range of cells, use a colon (:) to separate the reference to the first cell in the range and the reference to the last cell in the range. For example, A1:A5.
Enter all required arguments     Some functions have required arguments. Also, make sure that you have not entered too many arguments.
Nest no more than 64 functions     You can enter, or nest, no more than 64 levels of functions within a function.
Enclose other sheet names in single quotation marks     If the formula refers to values or cells on other worksheets or workbooks, and the name of the other workbook or worksheet contains a nonalphabetical character, you must enclose its name within single quotation marks ( ' ).
Include the path to external workbooks     Make sure that each external reference (external reference: A reference to a cell or range on a sheet in another Excel workbook, or a reference to a defined name in another workbook.) contains a workbook name and the path to the workbook.
Enter numbers without formatting     Do not format numbers as you enter them in formulas. For example, even if the value that you want to enter is $1,000, enter 1000 in the formula.

Top of Page Top of Page

 
 
Applies to:
Excel 2010