0% found this document useful (0 votes)
363 views134 pages

COUNT Function

The COUNT function counts the number of cells that contain numbers within the specified range or array. It will count numbers, dates, or text that can be interpreted as numbers, but does not count logical values, text that isn't a number, or error values. The COUNTIF function counts cells that meet criteria, allowing you to count cells based on a condition like containing a certain value or number. The COUNTA function counts all non-empty cells, including numbers, text, logical values, and errors.

Uploaded by

Wen Wen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
363 views134 pages

COUNT Function

The COUNT function counts the number of cells that contain numbers within the specified range or array. It will count numbers, dates, or text that can be interpreted as numbers, but does not count logical values, text that isn't a number, or error values. The COUNTIF function counts cells that meet criteria, allowing you to count cells based on a condition like containing a certain value or number. The COUNTA function counts all non-empty cells, including numbers, text, logical values, and errors.

Uploaded by

Wen Wen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 134

COUNT function

The COUNT function counts the number of cells that contain numbers, and counts
numbers within the list of arguments. Use the COUNT function to get the number of
entries in a number field that is in a range or array of numbers. For example, you can enter
the following formula to count the numbers in the range A1:A20:

=COUNT(A1:A20)

In this example, if five of the cells in the range contain numbers, the result is 5.

Syntax
COUNT(value1, [value2], ...)

The COUNT function syntax has the following arguments:

 value1 Required. The first item, cell reference, or range within which you want to
count numbers.
 value2, ... Optional. Up to 255 additional items, cell references, or ranges within
which you want to count numbers.

Note The arguments can contain or refer to a variety of different types of data, but only
numbers are counted.

Remarks
 Arguments that are numbers, dates, or a text representation of numbers (for example,
a number enclosed in quotation marks, such as "1") are counted.
 Logical values and text representations of numbers that you type directly into the list
of arguments are counted.
 Arguments that are error values or text that cannot be translated into numbers are
not counted.
 If an argument is an array or reference, only numbers in that array or reference are
counted. Empty cells, logical values, text, or error values in the array or reference are
not counted.
 If you want to count logical values, text, or error values, use the COUNTA function.
 If you want to count only numbers that meet certain criteria, use the COUNTIF
function or the COUNTIFS function.
Example
Copy the example data in the following table, and paste it in cell A1 of a new Excel
worksheet. For formulas to show results, select them, press F2, and then press Enter. If you
need to, you can adjust the column widths to see all the data.

Data
12/8/08

19
22.24
TRUE
#DIV/0!
Formula Description Result
Counts the number of cells that contain numbers in cells A2
=COUNT(A2:A7) 3
through A7.
Counts the number of cells that contain numbers in cells A5
=COUNT(A5:A7) 2
through A7.
Data
Counts the number of cells that contain numbers in cells A2
=COUNT(A2:A7,2) 4
through A7, and the value 2

Applies To: Excel 2013, Excel 2007, Excel 2010, Excel Starter, Excel Online, Excel for Mac
2011, Excel 2016 for Mac

COUNTIF function
Use COUNTIF, one of the statistical functions, to count the number of cells that meet a
criterion; for example, to count the number of times a particular city appears in a customer
list.

Syntax
COUNTIF(range, criteria)
For example:

 =COUNTIF(A2:A5,"apples")
 =COUNTIF(A2:A5,A4)

Argument name Description


The group of cells you want to count. Range can contain numbers,
arrays, or references that contain numbers. Blank and text values are
range (required) ignored.

Learn how to select ranges in a worksheet.


A number, expression, cell reference, or text string that determines
which cells will be counted.

For example, you can use a number like 32, a comparison like ">32", a
criteria (required)
cell like B4, or a word like "apples".

COUNTIF uses only a single criteria. Use COUNTIFS if you want to use
multiple criteria.

Examples
To use these examples in Excel, copy the data in the table below, and paste it in cell A1 of a
new worksheet.

Data Data
Apples 32
Oranges 54
Peaches 75
Apples 86
Formula Description
Counts the number of cells with apples in cells
=COUNTIF(A2:A5,"apples")
A2 through A5. The result is 2.
Counts the number of cells with peaches
=COUNTIF(A2:A5,A4) (using criterion in A4) in cells A2 through A5.
The result is 1.
Counts the number with oranges (using
=COUNTIF(A2:A5,A3)+COUNTIF(A2:A5,A2) criterion in A3) and apples (using criterion in
A2) in cells A2 through A5. The result is 3.
Data Data
Counts the number of cells with a value
=COUNTIF(B2:B5,">55") greater than 55 in cells B2 through B5. The
result is 2.
Counts the number of cells with a value not
equal to 75 in cells B2 through B5. The
ampersand (&) merges the comparison
=COUNTIF(B2:B5,"<>"&B4)
operator for not equal to (<>) and the value
in B4 to read =COUNTIF(B2:B5,"<>75"). The
result is 3.
Counts the number of cells with a value
=COUNTIF(B2:B5,">=32")- greater than (>) or equal to (=) 32 and less
COUNTIF(B2:B5,">85") than (<) or equal to (=) 85 in cells B2 through
B5. The result is 3.
Counts the number of cells containing any
text in cells A2 through A5. The asterisk (*) is
=COUNTIF(A2:A5,"*")
used as the wildcard character to match any
character. The result is 4.
Data Data
Counts the number of cells that have exactly 7
characters that end with the letters "es" in cells
=COUNTIF(A2:A5,"?????es") A2 through A5. The question mark (?) is used
as the wildcard character to match individual
characters. The result is 2.

Common Problems
Problem What went wrong
The COUNTIF function returns incorrect results when you use it to
Wrong value match strings longer than 255 characters.
returned for long To match strings longer than 255 characters, use the CONCATENATE
strings. function or the concatenate operator &. For example,
=COUNTIF(A2:A5,"long string"&"another long string").
No value returned
when you expect a Be sure to enclose the criteria argument in quotes.
value.
Best practices
Do this Why
Be aware that
COUNTIF ignores Criteria aren't case sensitive. In other words, the string "apples" and
upper and lower case the string "APPLES" will match the same cells.
in text strings.
Wildcard characters —the question mark (?) and asterisk (*)—can
be used in criteria. A question mark matches any single character.
An asterisk matches any sequence of characters. If you want to find
Use wildcard an actual question mark or asterisk, type a tilde (~) in front of the
characters. character.

For example, =COUNTIF(A2:A5,"apple?") will count all instances of


"apple" with a last letter that could vary.
When counting text values, make sure the data doesn't contain
Make sure your data leading spaces, trailing spaces, inconsistent use of straight and curly
doesn't contain quotation marks, or nonprinting characters. In these cases,
erroneous characters. COUNTIF might return an unexpected value.
Do this Why
You may need to remove trailing spaces in a cell after table values
to get accurate results. Try using the CLEAN function or the TRIM
function.

Related
 To count cells that aren't blank, use the COUNTA function.
 To count cells using multiple criteria, use the COUNTIFS function.
 Use the CLEAN function or the TRIM function to remove leading spaces in table
values.
 Learn more about errors in worksheets, like #N/A, #REF, and #Name?.
 See a video on how to use the COUNTIFS function.

Applies To: Excel 2013, Excel 2007, Excel 2010, Excel Starter, Excel Online, Excel for Mac
2011, Excel 2016 for Mac
COUNTA function
The COUNTA function counts the number of cells that are not empty in a range.

Syntax
COUNTA(value1, [value2], ...)

The COUNTA function syntax has the following arguments:

 value1 Required. The first argument representing the values that you want to count.
 value2, ... Optional. Additional arguments representing the values that you want to
count, up to a maximum of 255 arguments.

Remarks
 The COUNTA function counts cells containing any type of information, including error
values and empty text (""). For example, if the range contains a formula that returns an
empty string, the COUNTA function counts that value. The COUNTA function does
not count empty cells.
 If you do not need to count logical values, text, or error values (in other words, if you
want to count only cells that contain numbers), use the COUNT function.
 If you want to count only cells that meet certain criteria, use the COUNTIF function or
the COUNTIFS function.

Example
Copy the example data in the following table, and paste it in cell A1 of a new Excel
worksheet. For formulas to show results, select them, press F2, and then press Enter. If you
need to, you can adjust the column widths to see all the data.

Data
39790

19
22.24
TRUE
#DIV/0!
Data
Formula Description Result
=COUNTA(A2:A7) Counts the number of nonblank cells in cells A2 through A7. 5

Applies To: Excel 2013, Excel 2007, Excel 2010, Excel Starter, Excel Online, Excel for Mac
2011, Excel 2016 for Mac

COUNTBLANK
function
Counts empty cells in a specified range of cells.
Syntax
COUNTBLANK(range)

The COUNTBLANK function syntax has the following arguments:

 Range Required. The range from which you want to count the blank cells.

Remark
Cells with formulas that return "" (empty text) are also counted. Cells with zero values are
not counted.

To run this formula, you need to turn off iterative calculation. Here's how:

1. Click the File tab, and then click Options.


2. Click Formulas, and under Calculation options, clear the Enable iterative calculation
check box, then click OK.
Example
Copy the example data in the following table, and paste it in cell A1 of a new Excel
worksheet. For formulas to show results, select them, press F2, and then press Enter. If you
need to, you can adjust the column widths to see all the data.

Data Data

6
27
4 34
Formula Description Result
Counts empty cells in the range above. The formula returns
=COUNTBLANK(A2:B5) 4
empty text.
Note You need to turn iterative calculation off to run this
formula. Click the File tab, click Options, click Formulas, and
under Calculation options, clear the Enable iterative
calculation check box.
Applies To: Excel 2013, Excel 2007, Excel 2010, Excel Starter, Excel Online, Excel for Mac
2011, Excel 2016 for Mac

DATEDIF function
Calculates the number of days, months, or years between two dates. This function is
provided for compatibility with Lotus 1-2-3.

Syntax
DATEDIF(start_date,end_date,unit)

Start_date A date that represents the first, or starting, date of the period. Dates may be
entered as text strings within quotation marks (for example, "2001/1/30"), as serial numbers
(for example, 36921, which represents January 30, 2001, if you're using the 1900 date
system), or as the results of other formulas or functions (for example,
DATEVALUE("2001/1/30")).

End_date A date that represents the last, or ending, date of the period.
Unit The type of information that you want returned:

Unit Returns
"Y" The number of complete years in the period.
"M" The number of complete months in the period.
"D" The number of days in the period.
The difference between the days in start_date and end_date. The months and years
"MD"
of the dates are ignored.
The difference between the months in start_date and end_date. The days and years
"YM"
of the dates are ignored
The difference between the days of start_date and end_date. The years of the dates
"YD"
are ignored.

Remarks
 Dates are stored as sequential serial numbers so they can be used in calculations. By
default, December 31, 1899 is serial number 1, and January 1, 2008 is serial number
39448 because it is 39,448 days after January 1, 1900.
 The DATEDIF function is useful in formulas where you need to calculate an age.
Examples
Description
Start_date End_daTe Formula
(Result)
Two
complete
1/1/2001 1/1/2003 =DATEDIF(Start_date,End_date,"Y")
years in the
period (2)
440 days
between
June 1,
6/1/2001 8/15/2002 =DATEDIF(Start_date,End_date,"D")
2001, and
August 15,
2002 (440)
75 days
between
6/1/2001 8/15/2002 =DATEDIF(Start_date,End_date,"YD") June 1 and
August 15,
ignoring the
Description
Start_date End_daTe Formula
(Result)
years of the
dates (75)
The
difference
between 1
and 15 —
the day of
start_date
and the day
6/1/2001 8/15/2002 =DATEDIF(Start_date,End_date,"MD")
of
end_date —
ignoring the
months and
the years of
the dates
(14)

Applies To: Excel 2013, Excel 2007, Excel 2010, SharePoint Server 2007, SharePoint Server
SUMIF function
You use the SUMIF function to sum the values in a range that meet criteria that you specify.
For example, suppose that in a column that contains numbers, you want to sum only the
values that are larger than 5. You can use the following formula:

=SUMIF(B2:B25,">5")

In this example, the criteria is applied to the values that are being summed. If you want,
you can apply the criteria to one range and sum the corresponding values in a different
range. For example, the formula =SUMIF(B2:B5, "John", C2:C5) sums only the values in the
range C2:C5, where the corresponding cells in the range B2:B5 equal "John."

Note To sum cells based on multiple criteria, see SUMIFS function.

Syntax
SUMIF(range, criteria, [sum_range])
The SUMIF function syntax has the following arguments:

 range Required. The range of cells that you want evaluated by criteria. Cells in each
range must be numbers or names, arrays, or references that contain numbers. Blank
and text values are ignored.
 criteria Required. The criteria in the form of a number, expression, a cell reference,
text, or a function that defines which cells will be added. For example, criteria can be
expressed as 32, ">32", B5, "32", "apples", or TODAY().

Important Any text criteria or any criteria that includes logical or mathematical
symbols must be enclosed in double quotation marks ("). If the criteria is numeric,
double quotation marks are not required.

 sum_range Optional. The actual cells to add, if you want to add cells other than
those specified in the range argument. If the sum_range argument is omitted, Excel
adds the cells that are specified in the range argument (the same cells to which the
criteria is applied).

 You can use the wildcard characters—the question mark (?) and asterisk (*)—as the
criteria argument. A question mark matches any single character; an asterisk matches
any sequence of characters. If you want to find an actual question mark or asterisk,
type a tilde (~) preceding the character.
Remarks
 The SUMIF function returns incorrect results when you use it to match strings longer
than 255 characters or to the string #VALUE!.
 The sum_range argument does not have to be the same size and shape as the range
argument. The actual cells that are added are determined by using the upper leftmost
cell in the sum_range argument as the beginning cell, and then including cells that
correspond in size and shape to the range argument. For example:

If range is And sum_range is Then the actual cells are


A1:A5 B1:B5 B1:B5
A1:A5 B1:B3 B1:B5
A1:B4 C1:D4 C1:D4
A1:B4 C1:C2 C1:D4

However, when the range and sum_range arguments in the SUMIF function do not contain
the same number of cells, worksheet recalculation may take longer than expected.
Examples
Example 1

Copy the example data in the following table, and paste it in cell A1 of a new Excel
worksheet. For formulas to show results, select them, press F2, and then press Enter. If you
need to, you can adjust the column widths to see all the data.

Property Value Commission Data


$
$ 100,000.00 $ 7,000.00
250,000.00
$ 200,000.00 $ 14,000.00
$ 300,000.00 $ 21,000.00
$ 400,000.00 $ 28,000.00
Formula Description Result
Sum of the commissions for property values
=SUMIF(A2:A5,">160000",B2:B5) $ 63,000.00
over 160,000.
$
=SUMIF(A2:A5,">160000") Sum of the property values over 160,000.
900,000.00
Property Value Commission Data
Sum of the commissions for property values
=SUMIF(A2:A5,300000,B2:B5) $ 21,000.00
equal to 300,000.
Sum of the commissions for property values
=SUMIF(A2:A5,">" & C2,B2:B5) $ 49,000.00
greater than the value in C2.

Example 2

Copy the example data in the following table, and paste it in cell A1 of a new Excel
worksheet. For formulas to show results, select them, press F2, and then press Enter. If you
need to, you can adjust the column widths to see all the data.

Category Food Sales


$
Vegetables Tomatoes
2,300.00
$
Vegetables Celery
5,500.00
Fruits Oranges $ 800.00
Butter $ 400.00
Category Food Sales
$
Vegetables Carrots
4,200.00
Fruits Apples $ 1,200.00
Formula Description Result
Sum of the sales of all foods in the "Fruits" $
=SUMIF(A2:A7,"Fruits",C2:C7)
category. 2,000.00
Sum of the sales of all foods in the $
=SUMIF(A2:A7,"Vegetables",C2:C7)
"Vegetables" category. 12,000.00
Sum of the sales of all foods that end in "es" $
=SUMIF(B2:B7,"*es",C2:C7)
(Tomatoes, Oranges, and Apples). 4,300.00
Sum of the sales of all foods that do not
=SUMIF(A2:A7,"",C2:C7) $ 400.00
have a category specified.

Top of Page

Applies To: Excel 2013, Excel 2007, Excel 2010, Excel Starter, Excel Online, Excel for Mac
2011, Excel 2016 for Mac
TEXT function
This article describes the formula syntax and usage of the TEXT function in Microsoft Excel.

Description
The TEXT function converts a numeric value to text and lets you specify the display
formatting by using special format strings. This function is useful in situations where you
want to display numbers in a more readable format, or you want to combine numbers with
text or symbols. For example, suppose cell A1 contains the number 23.5. To format the
number as a dollar amount, you can use the following formula:

=TEXT(A1,"$0.00")

In this example, Excel displays $23.50.

You can also format numbers by using the commands in the Number group on the Home
tab of the Ribbon. However, these commands work only if the entire cell is numeric. If you
want to format a number and combine it with other text, the TEXT function is the best
option. For example, you can add text to the preceding formula:

=TEXT(A1,"$0.00") & " per hour"

Excel displays $23.50 per hour.

Syntax
TEXT(value, format_text)

The TEXT function syntax has the following arguments:

 value Required. A numeric value, a formula that evaluates to a numeric value, or a


reference to a cell containing a numeric value.
 format_text Required. A numeric format as a text string enclosed in quotation marks,
for example "m/d/yyyy" or "#,##0.00". See the following sections for specific
formatting guidelines.

Guidelines for number formats


Display decimal places and significant digits To format fractions or numbers
that contain decimal points, include the following digit placeholders, decimal
points, and thousand separators in the format_text argument.

Placeholder Description
Displays insignificant zeros if a number has fewer digits than there are zeros in
0 (zero) the format. For example, if you type 8.9, and you want it to be displayed as
8.90, use the format #.00.
Follows the same rules as the 0 (zero). However, Excel does not display extra
zeros when the number that you type has fewer digits on either side of the
#
decimal than there are # symbols in the format. For example, if the custom
format is #.##, and you type 8.9 in the cell, the number 8.9 is displayed.
Follows the same rules as the 0 (zero). However, Excel adds a space for
insignificant zeros on either side of the decimal point so that decimal points
?
are aligned in the column. For example, the custom format 0.0? aligns the
decimal points for the numbers 8.9 and 88.99 in a column.
. (period) Displays the decimal point in a number.

 If a number has more digits to the right of the decimal point than there are
placeholders in the format, the number rounds to as many decimal places as there are
placeholders. If there are more digits to the left of the decimal point than there are
placeholders, the extra digits are displayed. If the format contains only number signs
(#) to the left of the decimal point, numbers less than 1 begin with a decimal point; for
example, .47.

To display As Use this format


1234.59 1234.6 "####.#"
8.9 8.900 "#.000"
0.631 0.6 "0.#"
12 12.0
"#.0#"
1234.568 1234.57
44.398
44.398
102.65
102.65 "???.???"
2.8
2.8
(with aligned decimals)
5 1/4
5.25
5 3/10 "# ???/???"
5.3
(with aligned fractions)
 Display a thousands separator To display a comma as a thousands separator or to
scale a number by a multiple of 1,000, include the following separator in the number
format.

Displays the thousands separator in a number. Excel separates thousands by


commas if the format contains a comma that is enclosed by number signs (#) or
,
by zeros. A comma that follows a digit placeholder scales the number by 1,000.
(comma)
For example, if the format_text argument is "#,###.0,", Excel displays the number
12,200,000 as 12,200.0.
To display As Use this format
12000 12,000 "#,###"
12000 12 "#,"
12200000 12.2 "0.0,,"

Guidelines for date and time formats

 Display days, months, and years To display numbers as date formats (such as days,
months, and years), use the following codes in the format_text argument.

m Displays the month as a number without a leading zero.


mm Displays the month as a number with a leading zero when appropriate.
m Displays the month as a number without a leading zero.
mmm Displays the month as an abbreviation (Jan to Dec).
mmmm Displays the month as a full name (January to December).
mmmmm Displays the month as a single letter (J to D).
D Displays the day as a number without a leading zero.
dd Displays the day as a number with a leading zero when appropriate.
ddd Displays the day as an abbreviation (Sun to Sat).
dddd Displays the day as a full name (Sunday to Saturday).
yy Displays the year as a two-digit number.
yyyy Displays the year as a four-digit number.
To display As Use this format
Months 1–12 "m"
Months 01–12 "mm"
Months Jan–Dec "mmm"
Months January–December "mmmm"
Months J–D "mmmmm"
Days 1–31 "d"
Days 01–31 "dd"
To display As Use this format
Days Sun–Sat "ddd"
Days Sunday–Saturday "dddd"
Years 00–99 "yy"
Years 1900–9999 "yyyy"

 Display hours, minutes, and seconds To display time formats (such as hours,
minutes, and seconds), use the following codes in the format_text argument.

h Displays the hour as a number without a leading zero.


Displays elapsed time in hours. If you are working with a formula that
[h] returns a time in which the number of hours exceeds 24, use a number
format that resembles [h]:mm:ss.
Displays the hour as a number with a leading zero when appropriate. If the
hh format contains AM or PM, the hour is shown based on the 12-hour clock.
Otherwise, the hour is shown based on the 24-hour clock.
M Displays the minute as a number without a leading zero.
h Displays the hour as a number without a leading zero.
Note The m or the mm code must appear immediately after the h or hh
code or immediately before the ss code; otherwise, Excel displays the month
instead of minutes.
Displays elapsed time in minutes. If you are working with a formula that
[m] returns a time in which the number of minutes exceeds 60, use a number
format that resembles [mm]:ss.
Displays the minute as a number with a leading zero when appropriate.

mm Note The m or the mm code must appear immediately after the h or hh


code or immediately before the ss code; otherwise, Excel displays the month
instead of minutes.
S Displays the second as a number without a leading zero.
Displays elapsed time in seconds. If you are working with a formula that
[s] returns a time in which the number of seconds exceeds 60, use a number
format that resembles [ss].
Displays the second as a number with a leading zero when appropriate. If
ss you want to display fractions of a second, use a number format that
resembles h:mm:ss.00.
h Displays the hour as a number without a leading zero.
AM/PM, Displays the hour based on a 12-hour clock. Excel displays AM, am, A, or a
am/pm, A/P, for times from midnight until noon and PM, pm, P, or p for times from noon
a/p until midnight.
To display As Use this format
Hours 0–23 "h"
Hours 00–23 "hh"
Minutes 0–59 "m"
Minutes 00–59 "mm"
Seconds 0–59 "s"
Seconds 00–59 "ss"
Time 4 AM "h AM/PM"
Time 4:36 PM "h:mm AM/PM"
Time 4:36:03 P "h:mm:ss A/P"
Time 4:36:03.75 "h:mm:ss.00"
Elapsed time (hours and minutes) 1:02 "[h]:mm"
Elapsed time (minutes and seconds) 62:16 "[mm]:ss"
Elapsed time (seconds and hundredths) 3735.80 "[ss].00"
Guidelines for currency, percentages, and scientific notation format

 Include currency symbols To precede a number with a dollar sign ($), type the dollar
sign at the beginning of the format_text argument (for example, "$#,##0.00"). To
enter one of the following currency symbols in a number format, press NUM LOCK
and use the numeric keypad to type the ANSI code for the symbol.

To enter Use this key combination


¢ ALT+0162
£ ALT+0163
¥ ALT+0165
ALT+0128

 Note You must use the numeric keypad; using the ALT key with the number keys in
the top row of the keyboard will not generate ANSI codes.
 Display percentages To display numbers as a percentage of 100 — for example, to
display .08 as 8% or 2.8 as 280% — include the percent sign (%) in the format_text
argument.
 Display scientific notations To display numbers in scientific (exponential) format, use
the following exponent codes in the format_text argument.
Displays a number in scientific (exponential) format. Excel displays a number to the
E (E-, right of the "E" or "e" that corresponds to the number of places that the decimal
E+, e-, point was moved. For example, if the format_text argument is "0.00E+00", Excel
e+) displays the number 12,200,000 as 1.22E+07. If you change the format_text
argument to "#0.0E+0", Excel displays 12.2E+6.

Guidelines for including text and adding spacing

 If you include any of the following characters in the format_text argument, they are
displayed exactly as entered.

$ Dollar sign
+ Plus sign
( Left parenthesis
: Colon
^ Circumflex accent (caret)
' Apostrophe
{ Left curly bracket
< Less-than sign
= Equal sign
$ Dollar sign
- Minus sign
/ Slash mark
) Right parenthesis
! Exclamation point
& Ampersand
~ Tilde
} Right curly bracket
> Greater-than sign
Space character

 The format_text argument cannot contain an asterisk (*).


 Using the TEXT function converts a numeric value to formatted text, and the result can
no longer be calculated as a number. To format a cell so that its value remains
numeric, right-click the cell, click Format Cells, and then in the Format Cells dialog
box, on the Number tab, set the formatting options you want. For more information
about using the Format Cells dialog box, click the Help button (?) in the upper right
corner of the dialog box.
Example
Copy the example data in the following table, and paste it in cell A1 of a new Excel
worksheet. For formulas to show results, select them, press F2, and then press Enter. If you
need to, you can adjust the column widths to see all the data.

Salesperson Sales Data


Burke $2,800 39300.63
Dykstra 40%
Formula Description Result
=A2&" sold "&TEXT(B2, Combines cell A2, the text string " sold," cell Burke sold
"$0.00")&" worth of B2 (formatted as currency), and the text string $2800.00 worth of
units." " worth of units." into a phrase. units.
=A3&" had "&TEXT(B3, Combines cell A3, the string " sold," cell B3
Dykstra had 40%
"0%")&" of the total (formatted as a percentage), and the text
of the total sales.
sales." string " of the total sales." into a phrase.
="Date: " & TEXT(C2, Displays the value in C2 in a 4-digit year, 2-
Date: 2007-08-06
"yyyy-mm-dd") digit month, 2-digit day format.
Salesperson Sales Data
="Date-time: " &
Displays the value in C2 in a short date, 12- Date-time:
TEXT(C2, "m/d/yyyy
hour time format. 8/6/2007 3:07 PM
h:mm AM/PM")
Displays the value in C2 in scientific
=TEXT(C2, "0.00E+00") 3.93E+04
(exponential) format.
Displays the value in C2 in a currency format,
=TEXT(C2, "$#,##0.00") $39,300.63
with a thousands separator.

Applies To: Excel 2013, Excel 2007, Excel 2010, Excel Starter, Excel Online, Excel for Mac
2011, Excel 2016 for Mac
CONCATENATE
function
Use CONCATENATE, one of the text functions, to join two or more text strings into one
string.

Syntax: CONCATENATE(text1, [text2], ...)

For example:

 =CONCATENATE("Stream population for ", A2, " ", A3, " is ", A4, "/mile.")
 =CONCATENATE(B2, " ",C2)

Argument name Description


The first item to join. The item can be a text value, number, or cell
text1 (required)
reference.
Argument name Description
Text2, Additional text items to join. You can have up to 255 items, up to a
... (optional) total of 8,192 characters.

Examples
To use these examples in Excel, copy the data in the table below, and paste it in cell A1 of a
new worksheet.

Data
brook trout Andreas Hauser
Species Fourth Pine
32
Formula Description
=CONCATENATE("Stream Creates a sentence by joining the data in
population for ", A2, " ", A3, " is ", column A with other text. The result is Stream
A4, "/mile.") population for brook trout species is 32/mile.
Data
Joins three things: the string in cell B2, a space
=CONCATENATE(B2, " ", C2) character, and the value in cell C2. The result is
Andreas Hauser.
Joins three things: the string in cell C2, a string
=CONCATENATE(C2, ", ", B2) with a comma and a space character, and the
value in cell B2. The result is Andreas, Hauser.
Joins three things: the string in cell B3, a string
consisting of a space with ampersand and
=CONCATENATE(B3, " & ", C3)
another space, and the value in cell C3. The
result is Fourth & Pine.
Joins the same items as the previous example,
but by using the ampersand (&) calculation
=B3 & " & " & C3
operator instead of the CONCATENATE
function. The result is Fourth & Pine.
Common Problems
Problem Description
Use commas to separate adjoining text items. For example: Excel will
Quotation marks display =CONCATENATE("Hello ""World") as Hello"World with an
appear in result extra quote mark because a comma between the text arguments was
string. omitted.

Numbers don't need to have quotation marks.


Without designated spaces between separate text entries, the text
entries will run together. Add extra spaces as part of the
CONCATENATE formula. There are two ways to do this:

Words are jumbled  Add double quotation marks with a space between them " ". For
together. example: =CONCATENATE("Hello", " ", "World!").
 Add a space after the Text argument. For example:
=CONCATENATE("Hello ", "World!"). The string "Hello " has an
extra space added.
Problem Description
The #NAME? error
#NAME? usually means there are quotation marks missing from a
appears instead of
Text argument.
the expected result.

Best practices
Do this Description
The ampersand (&) calculation operator lets you join text
items without having to use a function.

Use the ampersand & For example,=A1 & B1 returns the same value
character instead of the as=CONCATENATE(A1,B1). In many cases, using the
CONCATENATE function. ampersand operator is quicker and simpler than using
CONCATENATE to create strings.

Learn more about using operation calculators.


Use the TEXT function to The TEXT function converts a numeric value to text and
combine and format strings. combines numbers with text or symbols.
Do this Description
For example, if cell A1 contains the number 23.5, you can use
the following formula to format the number as a dollar
amount:

=TEXT(A1,"$0.00")

Result: $23.50

Related
 Use the TEXT function to combine and format strings.
 Learn more about using operation calculators.
 View a video on how to use the CONCATENATE function.

Applies To: Excel 2013, Excel 2007, Excel 2010, Excel Starter, Excel Online, Excel for Mac
2011, Excel 2016 for Mac
Change text to upper,
lower, or proper
(normal) font
If you need to quickly change the text case to uppercase, lowercase, or proper (normal)
case, use Flash Fill instead of retyping all the text.

For example, column A has a list of names in lower case. Here's how you can change the
names to proper case.

1. In cell B2 or the column next to your data, type the first and last name with the first
letter in each name capitalized and press Enter.
2. Press Ctrl+E, or click Data > Flash Fill.

Flash Fill automatically fills in the rest of the names in column B, in the proper case.

Inconsistent capitalization? Use functions


Flash Fill works best on consistent data and doesn’t work on text that’s mistyped like this.
With inconsistent text, use functions to change the case of existing text. Since all of the
following functions work the same, we’ll see how to use just one of them.

 PROPER function – capitalizes the first letter in each word.


 UPPER function – changes text to all uppercase.
 LOWER function – changes text to all lowercase.
Change text to proper case with the PROPER function

1. To change Annik’s name to proper case, select cell B1. Type =PROPER(A1), and press
Enter.
2. To copy the formula down through cell B5, double-click the green square in the
lower-right corner of cell B1.

The names in column B are all in proper case.

Get rid of the first column

Just deleting the column of mistyped names might result in formula errors (#REF!). Here's
how to remove the column:
1. Copy the names in column B by dragging down the column and pressing Ctrl+C.
2. Right-click cell A1.
3. Click Paste Special > Values > OK to paste the names in column A without the
formulas.
4. Select column B.
5. Right-click the selection, and pick Delete > Entire Column > OK.

Applies To: Excel 2013

IF function
Use the IF function, one of the logical functions, to return one value if a condition is true
and another value if it's false.

Syntax
IF(logical_test, value_if_true, [value_if_false])
For example:

 =IF(A2>B2,"Over Budget","OK")
 =IF(A4=500,B4-A4,""

Argument name Description


logical_test (required) The condition you want to test.
The value that you want returned if the result of logical_test is
value_if_true (required)
TRUE.
The value that you want returned if the result of logical_test is
value_if_false (optional)
FALSE.

Examples
Copy the example data in the following table, and paste it in cell A1 of a new Excel
worksheet. To see the formula in a formula cell, select the cell and press F2.

Actual Expense Predicted Expense


$1,500 $900
$500 $900
$500 $925
=IF(A2>B2,"Over Because the actual expense of $1500 (A2) exceeded the
Budget","OK") predicted expense of $900 (B2), the result is Over Budget .
=IF(A2<B2,TRUE,
The first IF function is false. Therefore, the second IF statement is
IF(A3>B3,"over
calculated and because it too is false, the result is OK.
budget","OK"))
Because A4 equals 500, the Actual Expense $500 is subtracted
from Predicted Expense $925 to tell you how much over budget
=IF(A4=500,B4-A4,"")
you are. The result is 425. If A4 didn't equal 500, then empty text
("") would be returned.
=IF(A2<B2,TRUE,
The first IF function is false. Therefore, the second IF statement is
IF(A3>B3,"over
calculated and because it too is false, the result is OK.
budget","OK"))

Common Problems
Problem What went wrong
There was no argument for either value_if_true or value_if_False arguments. To
O (zero) in
see the right value returned, add argument text to the two arguments, or add
cell
TRUE or FALSE to the argument.
Problem What went wrong
#NAME?
This usually means that the formula is misspelled .
in cell

Best practices
Do this Why
Using an IF
Up to 64 IF functions can be nested within each other for value_if_true
function within
and value_if_false arguments to construct more elaborate tests.
another IF.
If any of the arguments to the IF function are arrays, every element of
Use IF with arrays the array is evaluated when the IF statement is carried out. Learn how
to create an array formula.

Related
 Read an Overview of formulas. You'll learn all about the bits and pieces that make
them up.
 Learn now to Use nested functions in a formula.
 Why is my formula broken?
 Excel has additional functions that can be used to analyze your data based on a
condition. For example, to count the number of occurrences of a string of text or a
number within a range of cells, use the COUNTIF or the COUNTIFS worksheet
functions.

To calculate a sum based on a string of text or a number within a range, use the
SUMIF or the SUMIFS worksheet functions.

 See a video on how to use the IF function.

Applies To: Excel 2013, Excel 2007, Excel 2010, Excel Starter, Excel Online, Excel for Mac
2011, Excel 2016 for Mac
Overview of formulas
in Excel
Important The calculated results of formulas and some Excel worksheet functions may
differ slightly between a Windows PC using x86 or x86-64 architecture and a Windows RT
PC using ARM architecture. Learn more about the differences.

If you're new to Excel, you'll soon find that it's more than just a grid in which you enter
numbers in columns or rows. Yes, you can use Excel to find totals for a column or row of
numbers, but you can also calculate a mortgage payment, solve math or engineering
problems, or find a best case scenario based on variable numbers that you plug in.

Excel does this by using formulas in cells. A formula performs calculations or other actions
on the data in your worksheet. A formula always starts with an equal sign (=), which can be
followed by numbers, math operators (such as a plus or minus sign), and functions, which
can really expand the power of a formula.

For example, the following formula multiplies 2 by 3 and then adds 5 to that result to come
up with the answer, 11.

=2*3+5

This next formula uses the PMT function to calculate a mortgage payment ($1,073.64),
which is based on a 5 percent interest rate (5% divided by 12 months equals the monthly
interest rate) over a 30-year period (360 months) for a $200,000 loan:

=PMT(0.05/12,360,200000)

Here are some additional examples of formulas that you can enter in a worksheet.

 =A1+A2+A3 Adds the values in cells A1, A2, and A3.


 =SQRT(A1) Uses the SQRT function to return the square root of the value in A1.
 =TODAY() Returns the current date.
 =UPPER("hello") Converts the text "hello" to "HELLO" by using the UPPER
worksheet function.
 =IF(A1>0) Tests the cell A1 to determine if it contains a value greater than 0.
In this article
The parts of an Excel formula

Using constants in Excel formulas

Using calculation operators in Excel formulas

Using functions and nested functions in Excel formulas

Using references in Excel formulas

Using names in Excel formulas

Using array formulas and array constants in Excel

The parts of an Excel formula


A formula can also contain any or all of the following: functions, references, operators, and
constants.
Parts of a formula

1. Functions: The PI() function returns the value of pi: 3.142...

2. References: A2 returns the value in cell A2.

3. Constants: Numbers or text values entered directly into a formula, such as 2.

4. Operators: The ^ (caret) operator raises a number to a power, and the * (asterisk)
operator multiplies numbers.

Top of Page

Using constants in Excel formulas


A constant is a value that is not calculated; it always stays the same. For example, the date
10/9/2008, the number 210, and the text "Quarterly Earnings" are all constants. An
expression or a value resulting from an expression is not a constant. If you use constants in
a formula instead of references to cells (for example, =30+70+110), the result changes only
if you modify the formula.

Top of Page

Using calculation operators in Excel formulas


Operators specify the type of calculation that you want to perform on the elements of a
formula. There is a default order in which calculations occur (this follows general
mathematical rules), but you can change this order by using parentheses.
Types of operators

There are four different types of calculation operators: arithmetic, comparison, text
concatenation, and reference.
Arithmetic operators

To perform basic mathematical operations, such as addition, subtraction, multiplication, or


division; combine numbers; and produce numeric results, use the following arithmetic
operators.
Arithmetic operator Meaning Example
+ (plus sign) Addition 3+3
Subtraction 3–1
– (minus sign)
Negation –1
* (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 operators, the result is a logical value — either TRUE or FALSE.

Comparison operator Meaning Example


= (equal sign) Equal to A1=B1
> (greater than sign) Greater than A1>B1
< (less than sign) Less than A1<B1
>= (greater than or equal to sign) Greater than or equal to A1>=B1
<= (less than or equal to sign) Less than or equal to A1<=B1
Comparison operator Meaning Example
<> (not equal to sign) Not equal to A1<>B1
Text concatenation operator

Use the ampersand (&) to concatenate (join) one or more text strings to produce a single
piece of text.

Text operator Meaning Example


& Connects, or concatenates, two values to "North"&"wind" results in
(ampersand) produce one continuous text value "Northwind"
Reference operators

Combine ranges of cells for calculations with the following operators.

Reference
Meaning Example
operator
Range operator, which produces one reference to all
: (colon) the cells between two references, including the two B5:B15
references.
Union operator, which combines multiple references
, (comma) SUM(B5:B15,D5:D15)
into one reference
Reference
Meaning Example
operator
Intersection operator, which produces one reference to
(space) B7:D7 C6:C8
cells common to the two references

The order in which Excel performs operations in formulas

In some cases, the order in which a calculation is performed can affect the return value of
the formula, so it's important to understand how the order is determined and how you can
change the order to obtain the results you want.
Calculation order

Formulas calculate values in a specific order. A formula in Excel always begins with an equal
sign (=). Excel interprets the characters that follow the equal sign as a formula. Following
the equal sign are the elements to be calculated (the operands), such as constants or cell
references. These are separated by calculation operators. Excel calculates the formula from
left to right, according to a specific order for each operator in the formula.
Operator precedence in Excel formulas

If you combine several operators in a single formula, Excel performs the operations in the
order shown in the following table. If a formula contains operators with the same
precedence — for example, if a formula contains both a multiplication and division
operator — Excel evaluates the operators from left to right.

Operator Description
: (colon)

(single space) Reference operators

, (comma)
– Negation (as in –1)
% Percent
^ Exponentiation
* and / Multiplication and division
+ and – Addition and subtraction
& Connects two strings of text (concatenation)
=
<>
<= Comparison
>=
<>
Use of parentheses in Excel formulas

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 performs
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 following example, the parentheses that enclose 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
Using functions and nested functions in Excel
formulas
Functions are predefined formulas that perform calculations by using specific values, called
arguments, in a particular order, or structure. Functions can be used to perform simple or
complex calculations.
The syntax of Excel functions

The following example of the ROUND function rounding off a number in cell A10 illustrates
the syntax of a function.

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.

2. Function name. For a list of available functions, click a cell and press SHIFT+F3.

3. Arguments. Arguments can be numbers, text, logical values such as TRUE or FALSE,
arrays, error values such as #N/A, or cell references. The argument you designate must
produce a valid value for that argument. Arguments can also be constants, formulas, or
other functions.

4. Argument tooltip. A tooltip with the syntax and arguments appears as you type the
function. For example, type =ROUND( and the tooltip appears. Tooltips appear only for
built-in functions.
Entering Excel functions

When you create a formula that contains a function, you can use the Insert Function dialog
box to help 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, 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 from
the drop-down list into the formula.
Nesting Excel 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.

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

Valid returns When a nested function is used as an argument, the nested function must
return the same type of value that the argument uses. For example, if the argument returns
a TRUE or FALSE value, the nested function must return a TRUE or FALSE value. If the
function doesn't, Excel displays a #VALUE! error value.
Nesting level limits A formula can contain up to seven levels of nested functions. When
one function (we'll call this Function B) is used as an argument in another function (we'll call
this Function A), Function B acts as a second-level function. For example, the AVERAGE
function and the SUM function are both second-level functions if they are used as
arguments of the IF function. A function nested within the nested AVERAGE function is then
a third-level function, and so on.

Top of Page

Using references in Excel formulas


A reference identifies a cell or a range of cells on a worksheet, and tells Excel where to look
for the values or data you want to use in a formula. You can use references to use data
contained in different parts of a worksheet in one formula or use the value from one cell in
several formulas. You can also refer to cells on other sheets in the same workbook, and to
other workbooks. References to cells in other workbooks are called links or external
references.
The A1 reference style
The default reference style By default, Excel uses the A1 reference style, which refers to
columns with letters (A through XFD, for a total of 16,384 columns) and refers to rows with
numbers (1 through 1,048,576). These letters and numbers are called row and column
headings. To refer to a cell, enter the column letter followed by the row number. For
example, B2 refers to the cell at the intersection of column B and row 2.

To refer to Use
The cell in column A and row 10 A10
The range of cells in column A and rows 10 through 20 A10:A20
The range of cells in row 15 and columns B through E B15:E15
All cells in row 5 5:5
All cells in rows 5 through 10 5:10
All cells in column H H:H
All cells in columns H through J H:J
The range of cells in columns A through E and rows 10 through 20 A10:E20

Making a reference to another worksheet In the following example, the AVERAGE


worksheet function calculates the average value for the range B1:B10 on the worksheet
named Marketing in the same workbook.
Reference to a range of cells on another worksheet in the same workbook

1. Refers to the worksheet named Marketing

2. Refers to the range of cells between B1 and B10, inclusively

3. Separates the worksheet reference from the cell range reference


The difference between absolute, relative and mixed references

Relative references A relative cell reference in a formula, such as A1, is based on the
relative position of the cell that contains the formula and the cell the reference refers to. If
the position of the cell that contains the formula changes, the reference is changed. If you
copy or fill the formula across rows or down columns, the reference automatically adjusts.
By default, new formulas use relative references. For example, if you copy or fill a relative
reference in cell B2 to cell B3, it automatically adjusts from =A1 to =A2.
Copied formula with relative reference

Absolute references An absolute cell reference in a formula, such as $A$1, always refer to
a cell in a specific location. If the position of the cell that contains the formula changes, the
absolute reference remains the same. If you copy or fill the formula across rows or down
columns, the absolute reference does not adjust. By default, new formulas use relative
references, so you may need to switch them to absolute references. For example, if you
copy or fill an absolute reference in cell B2 to cell B3, it stays the same in both cells: =$A$1.

Copied formula with absolute reference

Mixed references A mixed reference has either an absolute column and relative row, or
absolute row and relative column. An absolute column reference takes the form $A1, $B1,
and so on. An absolute row reference takes the form A$1, B$1, and so on. If the position of
the cell that contains the formula changes, the relative reference is changed, and the
absolute reference does not change. If you copy or fill the formula across rows or down
columns, the relative reference automatically adjusts, and the absolute reference does not
adjust. For example, if you copy or fill a mixed reference from cell A2 to B3, it adjusts from
=A$1 to =B$1.
Copied formula with mixed reference

The 3-D reference style

Conveniently referencing multiple worksheets If you want to analyze data in the same cell
or range of cells on multiple worksheets within a workbook, use a 3-D reference. A 3-D
reference includes the cell or range reference, preceded by a range of worksheet names.
Excel uses any worksheets stored between the starting and ending names of the reference.
For example, =SUM(Sheet2:Sheet13!B5) adds all the values contained in cell B5 on all the
worksheets between and including Sheet 2 and Sheet 13.

 You can use 3-D references to refer to cells on other sheets, to define names, and to
create formulas by using the following functions: SUM, AVERAGE, AVERAGEA,
COUNT, COUNTA, MAX, MAXA, MIN, MINA, PRODUCT, STDEV.P, STDEV.S, STDEVA,
STDEVPA, VAR.P, VAR.S, VARA, and VARPA.
 3-D references cannot be used in array formulas.
 3-D references cannot be used with the intersection operator (a single space) or in
formulas that use implicit intersection.
What occurs when you move, copy, insert, or delete worksheets The following examples
explain what happens when you move, copy, insert, or delete worksheets that are included
in a 3-D reference. The examples use the formula =SUM(Sheet2:Sheet6!A2:A5) to add cells
A2 through A5 on worksheets 2 through 6.

 Insert or copy If you insert or copy sheets between Sheet2 and Sheet6 (the
endpoints in this example), Excel includes all values in cells A2 through A5 from the
added sheets in the calculations.
 Delete If you delete sheets between Sheet2 and Sheet6, Excel removes their values
from the calculation.
 Move If you move sheets from between Sheet2 and Sheet6 to a location outside the
referenced sheet range, Excel removes their values from the calculation.
 Move an endpoint If you move Sheet2 or Sheet6 to another location in the same
workbook, Excel adjusts the calculation to accommodate the new range of sheets
between them.
 Delete an endpoint If you delete Sheet2 or Sheet6, Excel adjusts the calculation to
accommodate the range of sheets between them.
The R1C1 reference style

You can also use a reference style where both the rows and the columns on the worksheet
are numbered. The R1C1 reference style is useful for computing row and column positions
in macros. In the R1C1 style, Excel indicates the location of a cell with an "R" followed by a
row number and a "C" followed by a column number.

Reference Meaning
R[-2]C A relative reference to the cell two rows up and in the same column
R[2]C[2] A relative reference to the cell two rows down and two columns to the right
R2C2 An absolute reference to the cell in the second row and in the second column
R[-1] A relative reference to the entire row above the active cell
R An absolute reference to the current row

When you record a macro, Excel records some commands by using the R1C1 reference
style. For example, if you record a command, such as clicking the AutoSum button to insert
a formula that adds a range of cells, Excel records the formula by using R1C1 style, not A1
style, references.

You can turn the R1C1 reference style on or off by setting or clearing the R1C1 reference
style check box under the Working with formulas section in the Formulas category of the
Options dialog box. To display this dialog box, click the File tab.

Top of Page
Using names in Excel formulas
You can create defined names to represent cells, ranges of cells, formulas, constants, or
Excel tables. A name is a meaningful shorthand that makes it easier to understand the
purpose of a cell reference, constant, formula, or table, each of which may be difficult to
comprehend at first glance. The following information shows common examples of names
and how using them in formulas can improve clarity and make formulas easier to
understand.

Copy the example data in each of the following tables, and paste it in cell A1 of a new Excel
worksheet. For formulas to show results, select them, press F2, and then press Enter. If you
need to, you can adjust the column widths to see all the data.

Example 1

Exam
ple Example, using ranges instead of names Example, using names
type
Refere
=SUM(A16:A20) =SUM(Sales)
nce
Exam
ple Example, using ranges instead of names Example, using names
type
Const
=PRODUCT(A12,9.5%) =PRODUCT(Price,KCTaxRate)
ant
Formu =TEXT(VLOOKUP(MAX(A16,A20),A16:B20, =TEXT(VLOOKUP(MAX(Sales),SalesInfo,2
la 2,FALSE),"m/dd/yyyy") ,FALSE),"m/dd/yyyy")
Table A22:B25 =PRODUCT(Price,Table1[@Tax Rate])

Example 2

Exa
mpl Formula and result, using a
Example, not using a name Example, using a name
e name
type
Refe
renc '=SUM(A9:A13) '=SUM(Sales) =SUM(Sales)
e
Exa
mpl Formula and result, using a
Example, not using a name Example, using a name
e name
type
For '=TEXT(VLOOKUP(MAX(A9: '=TEXT(VLOOKUP(MAX(Sale =TEXT(VLOOKUP(MAX(Sale
mul 13),A9:B13,2,FALSE),"m/dd/ s),SalesInfo,2,FALSE),"m/dd/ s),SalesInfo,2,FALSE),"m/dd/
a yyyy") yyyy") yyyy")

Pric
e
$99
5

Sale
Sale Date
s
$24
3/17/2011
9
$39
4/2/2011
9
Exa
mpl Formula and result, using a
Example, not using a name Example, using a name
e name
type
$64
4/23/2011
3
$27
4/30/2011
5
$44
5/4/2011
7

Note: In the formulas in columns C and D, the defined name "Sales" is substituted for the
reference to (range) A9:A13 and the name "SalesInfo" is substituted for the range A9:B13.

To work more in-depth with the example data in Excel, download the embedded workbook
to your computer, and then open it in Excel.
Types of names

There are several types of names that 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. Also, 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 these names to make them more meaningful.

For more information about Excel tables, see Using structured references with Excel tables.
Creating and entering names

You create a name by using the:

 Name box on the formula bar This is best used for creating a workbook level name
for a selected range.
 Create a name from selection You can conveniently create names from existing row
and column labels by using a selection of cells in the worksheet.
 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.

You can enter a name by:

 Typing Typing the name, for example, as an argument to a formula.


 Using Formula AutoComplete Use the Formula AutoComplete drop-down list,
where valid names are automatically listed for you.
 Selecting from the Use in Formula command Select a defined name from a list
available from the Use in Formula command in the Defined Names group on the
Formula tab.

For more information, see Define and use names in formulas.

Top of Page

Using array formulas and array constants in


Excel
An array formula can perform multiple calculations and then return either a single result or
multiple results. Array formulas act on two or more sets of values known as array
arguments. Each array argument must have the same number of rows and columns. You
create array formulas in the same way that you create other formulas, except you press
CTRL+SHIFT+ENTER to enter the formula. Some of the built-in functions are array
formulas, and must be entered as arrays to get the correct results.

Array constants can be used in place of references when you don't want to enter each
constant value in a separate cell on the worksheet.
Using an array formula to calculate single and multiple results

When you enter an array formula, Excel automatically inserts the formula between { }
(braces).

To calculate a single result This type of array formula can simplify a worksheet model by
replacing several different formulas with a single array formula.

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

Array formula that produces a single result


When you enter the formula ={SUM(B2:D2*B3:D3)} as an array formula, it multiples the
Shares and Price for each stock, and then adds the results of those calculations together.

To calculate multiple results Some worksheet functions return arrays of values, or require
an array of values as an argument. To calculate multiple results with 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.

For example, given a series of three sales figures (in column B) for a series of three months
(in 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

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.
Using array constants
In an ordinary formula, you can enter a reference to a cell containing a value, or the value
itself, also called a constant. Similarly, in an array formula you can enter a reference to an
array, or enter the array of values contained within the cells, also called an array constant.
Array formulas accept constants in the same way that non-array formulas do, but you must
enter the array constants in a certain format.

Array constants can contain numbers, text, logical values such as TRUE or FALSE, or error
values such as #N/A. Different types of values can be in the same array constant — for
example, {1,3,4;TRUE,FALSE,TRUE}. Numbers in array constants can be in integer, decimal,
or scientific format. Text must be enclosed in double quotation marks — for example,
"Tuesday".

Array constants cannot contain cell references, columns or rows of unequal length,
formulas, or the special characters $ (dollar sign), parentheses, or % (percent sign).

When you format array constants, make sure you:

 Enclose them in braces ( { } ).


 Separate values in different columns by using commas (,). For example, to represent
the values 10, 20, 30, and 40, you enter {10,20,30,40}. This array constant is known as a
1-by-4 array and is equivalent to a 1-row-by-4-column reference.
 Separate values in different rows by using semicolons (;). For example, to represent
the values 10, 20, 30, and 40 in one row and 50, 60, 70, and 80 in the row immediately
below, you enter a 2-by-4 array constant: {10,20,30,40;50,60,70,80}.

Top of Page

Applies To: Excel 2013

LOOKUP function
Use LOOKUP, one of the lookup and reference functions, when you need to look in a
single row or column and find a value from the same position in a second row or column.

For example, let's say you know the part number for an auto part, but you don't know the
price. You can use the LOOKUP function to return the price in cell H2 when you enter the
auto part number in cell H1.
Use the LOOKUP function to search one row or one column. In the above example, we're
searching prices in column D.

Use VLOOKUP to search one row or column, or to search multiple rows and columns (like
a table). It's a much improved version of LOOKUP. Watch this video about how to use
VLOOKUP.

There are two ways to use LOOKUP: Vector


form and Array form
 Vector form: Use this form of LOOKUP to search one row or one column for a value.
Use the vector form when you want to specify the range that contains the values that
you want to match. For example, if you want to search for a value in column A, down
to row 6.
 Array form: We strongly recommend using VLOOKUP or HLOOKUP instead of the
array form. Watch this video about using VLOOKUP. The array form is provided for
compatibility with other spreadsheet programs, but it's functionality is limited.

An array is a collection of values in rows and columns (like a table) that you want to
search. For example, if you want to search columns A and B, down to row 6. LOOKUP
will return the nearest match. To use the array form, your data must be sorted.
Vector form
The vector form of LOOKUP looks in a one-row or one-column range (known as a vector)
for a value and returns a value from the same position in a second one-row or one-column
range.
Syntax

LOOKUP(lookup_value, lookup_vector, [result_vector])

The LOOKUP function vector form syntax has the following arguments:
 lookup_value Required. A value that LOOKUP searches for in the first vector.
Lookup_value can be a number, text, a logical value, or a name or reference that
refers to a value.
 lookup_vector Required. A range that contains only one row or one column. The
values in lookup_vector can be text, numbers, or logical values.

Important The values in lookup_vector must be placed in ascending order: ..., -2, -1,
0, 1, 2, ..., A-Z, FALSE, TRUE; otherwise, LOOKUP might not return the correct value.
Uppercase and lowercase text are equivalent.

 result_vector Optional. A range that contains only one row or column. The
result_vector argument must be the same size as lookup_vector. It has to be the same
size.
Remarks

 If the LOOKUP function can't find the lookup_value, the function matches the largest
value in lookup_vector that is less than or equal to lookup_value.
 If lookup_value is smaller than the smallest value in lookup_vector, LOOKUP returns the
#N/A error value.
Vector examples
You can try out these examples in your own Excel worksheet to learn how the LOOKUP
function works. In the first example, you're going to end up with a spreadsheet that looks
similar to this one:

1. Copy the data in following table, and paste it into a new Excel worksheet.
Copy this data into column A Copy this data into column B
Frequency Color

4.14 red
4.19 orange
5.17 yellow
5.77 green
6.39 blue

2. Next, copy the LOOKUP formulas from the following table into column D of your
worksheet.

Here's the
Copy this formula into
Here's what this formula does result you'll
the D column
see
Formula
=LOOKUP(4.19, Looks up 4.19 in column A, and returns the
Orange
A2:A6, B2:B6) value from column B that is in the same row.
Here's the
Copy this formula into
Here's what this formula does result you'll
the D column
see
Looks up 5.75 in column A, matches the nearest
=LOOKUP(5.75,
smaller value (5.17), and returns the value from Yellow
A2:A6, B2:B6)
column B that is in the same row.
Looks up 7.66 in column A, matches the nearest
=LOOKUP(7.66,
smaller value (6.39), and returns the value from blue
A2:A6, B2:B6)
column B that is in the same row.
Looks up 0 in column A, and returns an error
=LOOKUP(0, A2:A6,
because 0 is less than the smallest value (4.14) in #N/A
B2:B6)
column A.

3. For these formulas to show results, you may need to select them in your Excel
worksheet, press F2, and then press Enter. If you need to, adjust the column widths to
see all the data.

Top of Page

Array form
Tip We strongly recommend using VLOOKUP or HLOOKUP instead of the array form. See
this video about VLOOKUP; it provides examples. The array form of LOOKUP is provided
for compatibility with other spreadsheet programs, but it's functionality is limited.

The array form of LOOKUP looks in the first row or column of an array for the specified
value and returns a value from the same position in the last row or column of the array.
Use this form of LOOKUP when the values that you want to match are in the first row or
column of the array.
Syntax

LOOKUP(lookup_value, array)

The LOOKUP function array form syntax has these arguments:

 lookup_value Required. A value that LOOKUP searches for in an array. The


lookup_value argument can be a number, text, a logical value, or a name or reference
that refers to a value.
If LOOKUP can't find the value of lookup_value, it uses the largest value in the
array that is less than or equal to lookup_value.
If the value of lookup_value is smaller than the smallest value in the first row or
column (depending on the array dimensions), LOOKUP returns the #N/A error
value.
 array Required. A range of cells that contains text, numbers, or logical values that
you want to compare with lookup_value.

The array form of LOOKUP is very similar to the HLOOKUP and VLOOKUP functions.
The difference is that HLOOKUP searches for the value of lookup_value in the first row,
VLOOKUP searches in the first column, and LOOKUP searches according to the
dimensions of array.

If array covers an area that is wider than it is tall (more columns than rows),
LOOKUP searches for the value of lookup_value in the first row.
If an array is square or is taller than it is wide (more rows than columns), LOOKUP
searches in the first column.
With the HLOOKUP and VLOOKUP functions, you can index down or across, but
LOOKUP always selects the last value in the row or column.

Important The values in array must be placed in ascending order: ..., -2, -1, 0, 1,
2, ..., A-Z, FALSE, TRUE; otherwise, LOOKUP might not return the correct value.
Uppercase and lowercase text are equivalent.
Applies To: Excel 2013, Excel 2007, Excel 2010, Excel Starter, Excel Online, Excel for Mac
2011, Excel 2016 for Mac

VLOOKUP function
Use VLOOKUP, one of the lookup and reference functions, when you need to find things in
a table or a range by row. For example, look up an employee's last name by her employee
number, or find her phone number by looking up her last name (just like a telephone
book).

The secret to VLOOKUP is to organize your data so that the value you look up (employee’s
last name) is to the left of the return value you want to find (employee’s phone number).

Syntax
VLOOKUP (lookup_value, table_array, col_index_num, [range_lookup])

For example:
 =VLOOKUP(105,A2:C7,2,TRUE)
 =VLOOKUP("Fontana",B2:E7,2,FALSE)

Argument name Description


The value you want to look up. The value you want to look up
must be in the first column of the range of cells you specify in
table-array .
lookup_value (required)
For example, if table-array spans cells B2:D7, then your
lookup_value must be in column B. See the graphic below.
Lookup_value can be a value or a reference to a cell.
The range of cells in which the VLOOKUP will search for the
lookup_value and the return value.

The first column in the cell range must contain the


table_array (required) lookup_value (for example, Last Name in the picture below.)
The cell range also needs to include the return value (for
example, First Name in the graphic below) you want to find.

Learn how to select ranges in a worksheet.


Argument name Description
The column number (starting with 1 for the left-most column
col_index_num (required)
of table-array) that contains the return value.
A logical value that specifies whether you want VLOOKUP to
find an exact match or an approximate match:

 TRUE assumes the first column in the table is sorted either


range_lookup (optional) numerically or alphabetically, and will then search for the
closest value. This is the default method if you don't
specify one.
 FALSE searches for the exact value in the first column.

The following picture shows how you'd set up your worksheet with
=VLOOKUP("Akers",B2:D5,2,FALSE) to return Kim.
Examples
To use these examples in Excel, copy the data in the table below, and paste it in cell A1 of a
new worksheet.

First Birth
ID Last name Title
name date
Sale
12/8/196
101 Davis Sara s
8
Rep.
V.P.
of 2/19/195
102 Fontana Olivier
Sale 2
s
Sale
8/30/196
103 Leal Karina s
3
Rep.
Sale
Micha 9/19/195
104 Patten s
el 8
Rep.
Sale
s
105 Burke Brian 3/4/1955
Mgr
.
Sale
106 Sousa Luis s 7/2/1963
Rep.
Formula Description
Looks for the
value Fontana
in the first
column
(column B) of
table_array
B2:E7 and
returns the
=VLOOKUP("Fontana",B2:E7,2,FALSE)
value Olivier
found in the
second
column
(Column C) of
the
table_array.
The
range_lookup
FALSE returns
an exact
match.
Searches for
an exact
match of the
last name for
lookup_value10
=VLOOKUP(102,A2:C7,2,FALSE) 2 in column A.
Fontana is
returned. If
lookup_value is
105, Burke is
returned.
Checks to see
if the last
=IF(VLOOKUP(103,A1:E7,2,FALSE)="Sousa","Located",
name of
"Not found")
Employee with
ID 103 is
Sousa.
Because 103 is
actually Leal,
the result is
Not found. If
you change
"Sousa" to
"Leal" in the
formula, the
result is
Located.
For the fiscal
year 2014,
finds the age
of the
=INT(YEARFRAC(DATE(2014,6,30),
employee with
VLOOKUP(105,A2:E7,5, FALSE), 1))
ID 105. Uses
the YEARFRAC
function to
subtract the
birth date
from the fiscal
year end date
and displays
the result 59
as an integer
using the INT
function.
If there is an
employee with
ID 105,
displays the
employee's
=IF(ISNA(VLOOKUP(105,A2:E7,2,FALSE)) = TRUE,
last name,
"Employee not found",
which is Burke.
VLOOKUP(105,A2:E7,2,FALSE))
Otherwise,
displays the
message
Employee not
found. The
ISNA function
(see IS
functions)
returns a TRUE
value when
the VLOOKUP
function
returns the
#N/A error
value.
For the
employee with
ID 104,
=VLOOKUP(104,A2:E7,3,FALSE) & " " & concatenates
VLOOKUP(104,A2:E7,2,FALSE) & " is a " & (combines) the
VLOOKUP(104,A2:E7,4,FALSE) values of three
cells into the
complete
sentence
Michael Patten
is a Sales Rep.

Common Problems
Problem What went wrong
If range_lookup is TRUE or left out, the first column needs to be sorted
Wrong
alphabetically or numerically. If the first column isn't sorted, the return value
value
might be something you don't expect. Either sort the first column, or use
returned
FALSE for an exact match.
 If range_lookup is TRUE, then if the value in the lookup_value is smaller

than the smallest value in the first column of the table_array, you'll get
#N/A in the #N/A error value.
 If range_lookup is FALSE, the #N/A error value indicates that the exact
cell
number isn't found.

Learn more about errors in worksheets, like #N/A, #REF, and the rest.
#REF! in If col_index_num is greater than the number of columns in table-array, you'll
cell get the #REF! error value.
Problem What went wrong
#VALUE! in
If the table_array is less than 1, you'll get the #VALUE! error value.
cell
The #NAME? error value usually means that the formula is missing quotes. To
#NAME? in look up a person's name, make sure you use quotes around the name in the
cell formula. For example, enter the name as "Fontana" in
=VLOOKUP("Fontana",B2:E7,2,FALSE).

Best practices
Do this Why
Use absolute Using absolute references allows you to fill-down a formula so that it
references for always looks at the same exact lookup range.
range_lookup Learn how to use absolute cell references.
Don't store number When searching number or date values, be sure the data in the first
or date values as column of table_array isn't stored as text values. Otherwise,
text. VLOOKUP might return an incorrect or unexpected value.
Sort the first column of the table_array before using VLOOKUP when
Sort the first column
range_lookup is TRUE.
Do this Why
If range_lookup is FALSE and lookup_value is text, you can use the
wildcard characters—the question mark (?) and asterisk (*)—in
lookup_value. A question mark matches any single character. An
Use wildcard asterisk matches any sequence of characters. If you want to find an
characters actual question mark or asterisk, type a tilde (~) in front of the
character.

For example, =VLOOKUP("Fontan?",B2:E7,2,FALSE) will search for all


instances of Fontana with a last letter that could vary.
When searching text values in the first column, make sure the data in
the first column doesn't have leading spaces, trailing spaces,
Make sure your data inconsistent use of straight ( ' or " ) and curly ( ‘ or “) quotation
doesn't contain marks, or nonprinting characters. In these cases, VLOOKUP might
erroneous return an unexpected value.
characters.
To get accurate results, try using the CLEAN function or the TRIM
function to remove trailing spaces after table values in a cell.

Related
 View Quick Reference Card: VLOOKUP refresher for a refresher on best ways to use
VLOOKUP to look up data in tables.
 Learn how to create or change a cell reference.
 Learn how to sort data in a table alphabetically or numerically.
 VLOOKUP is a member of the lookup and reference functions, which includes the
HLOOKUP function.
 Use the CLEAN function or the TRIM function to remove leading spaces in table
values.
 Learn more about errors in worksheets, like #N/A, #REF, and the rest.
 See a video on how to use the VLOOKUP function.

Applies To: Excel 2013, Excel 2007, Excel 2010, Excel Starter, Excel Online, Excel for Mac
2011, Excel 2016 for Mac

HLOOKUP function
This article describes the formula syntax and usage of the HLOOKUP function in Microsoft
Excel.

Description
Searches for a value in the top row of a table or an array of values, and then returns a
value in the same column from a row you specify in the table or array. Use HLOOKUP
when your comparison values are located in a row across the top of a table of data, and
you want to look down a specified number of rows. Use VLOOKUP when your comparison
values are located in a column to the left of the data you want to find.

The H in HLOOKUP stands for "Horizontal."

Syntax
HLOOKUP(lookup_value, table_array, row_index_num, [range_lookup])

The HLOOKUP function syntax has the following arguments:

 Lookup_value Required. The value to be found in the first row of the table.
Lookup_value can be a value, a reference, or a text string.
 Table_array Required. A table of information in which data is looked up. Use a
reference to a range or a range name.
The values in the first row of table_array can be text, numbers, or logical values.
If range_lookup is TRUE, the values in the first row of table_array must be placed
in ascending order: ...-2, -1, 0, 1, 2,... , A-Z, FALSE, TRUE; otherwise, HLOOKUP
may not give the correct value. If range_lookup is FALSE, table_array does not
need to be sorted.
Uppercase and lowercase text are equivalent.
Sort the values in ascending order, left to right. For more information, see Sort
data in a range or table.
 Row_index_num Required. The row number in table_array from which the matching
value will be returned. A row_index_num of 1 returns the first row value in table_array,
a row_index_num of 2 returns the second row value in table_array, and so on. If
row_index_num is less than 1, HLOOKUP returns the #VALUE! error value; if
row_index_num is greater than the number of rows on table_array, HLOOKUP returns
the #REF! error value.
 Range_lookup Optional. A logical value that specifies whether you want HLOOKUP
to find an exact match or an approximate match. If TRUE or omitted, an approximate
match is returned. In other words, if an exact match is not found, the next largest
value that is less than lookup_value is returned. If FALSE, HLOOKUP will find an exact
match. If one is not found, the error value #N/A is returned.

Remark
 If HLOOKUP can't find lookup_value, and range_lookup is TRUE, it uses the largest
value that is less than lookup_value.
 If lookup_value is smaller than the smallest value in the first row of table_array,
HLOOKUP returns the #N/A error value.
 If range_lookup is FALSE and lookup_value is text, you can use the wildcard
characters, question mark (?) and asterisk (*), in lookup_value. A question mark
matches any single character; an asterisk matches any sequence of characters. If you
want to find an actual question mark or asterisk, type a tilde (~) before the character.

Example
Copy the example data in the following table, and paste it in cell A1 of a new Excel
worksheet. For formulas to show results, select them, press F2, and then press Enter. If you
need to, you can adjust the column widths to see all the data.
Axles Bearings Bolts
4 4 9
5 7 10
6 8 11
Formula Description Result
=HLOOKUP("Axles", A1:C4, 2, Looks up "Axles" in row 1, and returns the value from
4
TRUE) row 2 that's in the same column (column A).
=HLOOKUP("Bearings", A1:C4, Looks up "Bearings" in row 1, and returns the value
7
3, FALSE) from row 3 that's in the same column (column B).
Looks up "B" in row 1, and returns the value from
=HLOOKUP("B", A1:C4, 3, row 3 that's in the same column. Because an exact
5
TRUE) match for "B" is not found, the largest value in row 1
that is less than "B" is used: "Axles," in column A.
Looks up "Bolts" in row 1, and returns the value from
=HLOOKUP("Bolts", A1:C4, 4) 11
row 4 that's in the same column (column C).
Looks up the number 3 in the three-row array
=HLOOKUP(3,
constant, and returns the value from row 2 in the
{1,2,3;"a","b","c";"d","e","f"}, 2, c
same (in this case, third) column. There are three
TRUE)
rows of values in the array constant, each row
separated by a semicolon (;). Because "c" is found in
row 2 and in the same column as 3, "c" is returned.

Applies To: Excel 2013, Excel 2007, Excel 2010, Excel Starter, Excel Online, Excel for Mac
2011, Excel 2016 for Mac

Create a chart
Exploring charts in Excel and finding that the one you pick isn’t working well for your data is
a thing of the past! Try the Recommended Charts command on the Insert tab to quickly
create a chart that’s just right for your data.

1. Select the data for which you want to create a chart.


2. Click Insert > Recommended Charts.
3. On the Recommended Charts tab, scroll through the list of charts that Excel
recommends for your data, and click any chart to see how your data will look.
Tip If you don’t see a chart you like, click All Charts to see all available chart types.

4. When you find the chart you like, click it > OK.
5. Use the Chart Elements, Chart Styles, and Chart Filters buttons next to the upper-right
corner of the chart to add chart elements like axis titles or data labels, customize the
look of your chart, or change the data that’s shown in the chart.

6. To access additional design and formatting features, click anywhere in the chart to
add the Chart Tools to the ribbon, and then click the options you want on the Design
and Format tabs.
Tip If you’re using Office Professional Plus, you can also use Power View to create a chart.
For more about Power View, see Charts and other visualizations in Power View.

Top of Page

Applies To: Excel 2013

Use structured
references in Excel
table formulas
When you create an Excel table, Excel assigns a name to the table, and to each column in
the table. When you add formulas to an Excel table, those names can appear automatically
as you enter the formula and select the cell references in the table instead of manually
entering them. Here's an example of what Excel does:

Instead of using explicit cell references Excel uses table and column names
=Sum(C2:C7) =SUM(DeptSales[Sales Amount])

That combination of table and column names is called a structured reference. The names
in structured references adjust whenever you add or remove data from the table.

Structured references also appear when you create a formula outside of an Excel table that
references table data. The references can make it easier to locate tables in a large
workbook.

To include structured references in your formula, click the table cells you want to reference
instead of typing their cell reference in the formula. Let’s use the following example data to
enter a formula that automatically uses structured references to calculate the amount of a
sales commission.
Sales Person Region Sales Amount % Commission Com mission Am ount
Joe North 260 10%
Robert South 660 15%
Michelle East 940 15%
Erich West 410 12%
Dafna North 800 15%
Rob South 900 15%

1. Copy the sample data in the table above, including the column headings, and paste it
into cell A1 of a new, blank Excel worksheet.
2. To create the table, select cell A1, and press Ctrl+T.
3. Make sure the My table has headers box is checked and click OK.
4. In cell E2, type an equal sign (=), and click cell C2.

In the formula bar, the structured reference [@[Sales Amount]] appears after the equal
sign.

1. Type an asterisk (*) directly after the closing bracket., and click cell D2.

In the formula bar, the structured reference [@[% Commission]] appears after the asterisk.
1. Press Enter.

Excel automatically creates a calculated column and copies the formula down the entire
column for you, adjusting it for each row. For more information about formulas and
calculated columns, see Use formulas in an Excel table.

What do you want to learn about next?


What happens when I use explicit cell references?

How do I change a table name?

Structured reference syntax rules

Reference operators

Special item specifiers

Qualifying structured references in calculated columns

Examples of using structured references

Strategies for working with structured references


What happens when I use explicit cell
references?
If you enter explicit cell references in a calculated column, it can be harder to see what the
formula is calculating.

1. In your sample worksheet in Excel, click cell E2


2. In the formula bar, enter =C2*D2 and press Enter.

Notice that while Excel copies your formula down the column, it doesn't use structured
references. If, for example, you add a column between the existing columns C and D, you'd
have to revise your formula.

How do I change a table name?


When you create an Excel table, Excel creates a default table name (Table1, Table2, and so
on), but you can change the table name to make it more meaningful.

1. Select any cell in the Excel table to show the Table Tools on the ribbon.
2. On the Design tab, in the Table Name box, type the name you want, and press Enter.
In our example data, we used the name DeptSales.

Use the following rules for table names:

 Use v alid characters Always start a name with a letter, an underscore character (_), or
a backslash (\). Use letters, numbers, periods, and underscore characters for the rest
of the name.

You can’t use "C", "c", "R", or "r" for the name, because they’re already designated as a
shortcut for selecting the column or row for the active cell when you enter them in the
Name or Go To box.

 Don’t use c ell references Names can’t be the same as a cell reference, such as Z$100
or R1C1.
 Don’t use a s pace to separate words Spaces can’t be used in the name. You can use
no space or enter the underscore character (_) and period (.) as word separators. For
example, DeptSales, Sales_Tax or First.Quarter.
 Use no more than 255 characters A table name can have up to 255 characters.
 Use unique table names Duplicate names aren’t allowed. Excel doesn’t distinguish
between upper and lowercase characters in names so if you enter “Sales” but already
have another name called “SALES" in the same workbook, you’ll be prompted to
choose a unique name.
Structured reference syntax rules
You can also enter or change structured references manually in the formula but to do that,
it’ll help to understand the syntax of a structured reference. Let’s go over the following
formula example:

=SUM(DeptSales[[#Totals],[Sales Amount]],DeptSales[[#Data],[Commission Amount]])

This formula has the following structured reference components:

 Table name: DeptSales is a custom table name. It references the table data, without
any header or total rows. You can use a default table name, such as Table1, or change
it to use a custom name.
 Colum specifier: [Sales Amount] and [Commission Amount] are column specifiers
that use the names of the columns they represent. They reference the column data,
without any column header or total row. Always enclose specifiers in brackets as
shown.
 Item specifier: [#Totals] and [#Data] are special item specifiers that refer to specific
portions of the table, such as the total row.
 Table specifier: [[#Totals],[Sales Amount]] and [[#Data],[Commission Amount]] are
table specifiers that represent the outer portions of the structured reference. Outer
references follow the table name, and you enclose them in square brackets.
 Structures reference: (DeptSales[[#Totals],[Sales Amount]] and
DeptSales[[#Data],[Commission Amount]] are structured references, represented by a
string that begins with the table name and ends with the column specifier.

To create or edit structured references manually, use these syntax rules:

 Use brackets around specifiers All table, column, and special item specifiers need to
be enclosed in matching brackets ([ ]). A specifier that contains other specifiers
requires outer matching brackets to enclose the inner matching brackets of the other
specifiers. For example: =DeptSales[[Sales Person]:[Region]]
 All column headers are text strings But they don’t require quotes when they’re used
in a structured reference. Numbers or dates, such as 2014 or 1/1/2014, are also
considered text strings. You can’t use expressions with column headers. For example,
the expression DeptSalesFYSummary[[2014]:[2012]] won’t work.

Use brackets around column headers with special characters If there are special
characters, the entire column header needs to be enclosed in brackets, which means that
double brackets are required in a column specifier. For example:
=DeptSalesFYSummary[[Total $ Amount]]

Here’s the list of special characters that need extra brackets in the formula:

 Tab
 Line feed
 Carriage return
 Comma (,)
 Colon (:)
 Period (.)
 Left bracket ([)
 Right bracket (])
 Pound sign (#)
 Single quotation mark (')
 Double quotation mark (")
 Left brace ({)
 Right brace (})
 Dollar sign ($)
 Caret (^)
 Ampersand (&)
 Asterisk (*)
 Plus sign (+)
 Equal sign (=)
 Minus sign (-)
 Greater than symbol (>)
 Less than symbol (<)
 Division sign (/)

 Use an escape character for some special characters in column headers Some
characters have special meaning and require the use of a single quotation mark (') as
an escape character. For example: =DeptSalesFYSummary['#OfItems]

Here’s the list of special characters that need an escape character (‘) in the formula:

 Left bracket ([)


 Right bracket (])
 Pound sign(#)
 Single quotation mark (')

Use the space character to improve readability in a structured reference You can use
space characters to improve the readability of a structured reference. For example:
=DeptSales[ [Sales Person]:[Region] ] or =DeptSales[[#Headers], [#Data], [% Commission]]
It’s recommended to use one space:

 After the first left bracket ([)


 Preceding the last right bracket (]).
 After a comma.

Reference operators
For more flexibility in specifying ranges of cells, you can use the following reference
operators to combine column specifiers.

Which is
This structured reference: Refers to: By using the: cell
range:
All of the cells in two
: (colon) range
=DeptSales[[Sales Person]:[Region]] or more adjacent A2:B7
operator
columns
A combination of
=DeptSales[Sales , (comma) C2:C7,
two or more
Amount],DeptSales[Commission Amount] union operator E2:E7
columns
Which is
This structured reference: Refers to: By using the: cell
range:
The intersection of (space)
=DeptSales[[Sales Person]:[Sales Amount]]
two or more intersection B2:C7
DeptSales[[Region]:[% Commission]]
columns operator

Special item specifiers


To refer to specific portions of a table, such as just the totals row, you can use any of the
following special item specifiers in your structured references.

This special
Refers to:
item specifier:
#All The entire table, including column headers, data, and totals (if any).
#Data Just the data rows.
#Headers Just the header row.
#Totals Just the total row. If none exists, then it returns null.
This special
Refers to:
item specifier:
Just the cells in the same row as the formula. These specifiers can’t be
#This Row combined with any other special item specifiers. Use them to force implicit
intersection behavior for the reference or to override implicit intersection
or behavior and refer to single values from a column.
@ Excel automatically changes #This Row specifiers to the shorter @ specifier
or in tables that have more than one row of data. But if your table has only
one row, Excel doesn’t replace the #This Row specifier, which may cause
@[Column unexpected calculation results when you add more rows. To avoid
Name] calculation problems, make sure you enter multiple rows in your table
before you enter any structured reference formulas.

Qualifying structured references in calculated


columns
When you create a calculated column, you often use a structured reference to create the
formula. This structured reference can be unqualified or fully qualified. For example, to
create the calculated column, called Commission Amount, that calculates the amount of
commission in dollars, you can use the following formulas:

Type of structured
Example Comment
reference
Multiplies the corresponding values
Unqualified =[Sales Amount]*[% Commission]
from the current row.
=DeptSales[Sales
Multiples the corresponding values
Fully qualified Amount]*DeptSales[%
for each row for both columns.
Commission]

The general rule to follow is this: If you’re using structured references within a table, such as
when you create a calculated column, you can use an unqualified structured reference, but
if you use the structured reference outside of the table, you need to use a fully qualified
structured reference.

Examples of using structured references


Here are some ways to use structured references.
Which i s
This structured reference: Refers to: cell
range:
All the cells in the Sales Amount
=DeptSales[[#All],[Sales Amount]] C1:C8
column.
The header of the % Commission
=DeptSales[[#Headers],[% Commission]] D1
column.
The total of the Region column.
=DeptSales[[#Totals],[Region]] If there is no Totals row, then it B8
returns null.
=DeptSales[[#All],[Sales Amount]:[% All the cells in Sales Amount and
C1:D8
Commission]] % Commission.
Just the data of the %
=DeptSales[[#Data],[%
Commission and Commission D2:E7
Commission]:[Commission Amount]]
Amount columns.
Just the headers of the columns
=DeptSales[[#Headers],[Region]:[Commission
between Region and B1:E1
Amount]]
Commission Amount.
Which i s
This structured reference: Refers to: cell
range:
The totals of the Sales Amount
=DeptSales[[#Totals],[Sales through Commission Amount
C8:E8
Amount]:[Commission Amount]] columns. If there is no Totals
row, then it returns null.
=DeptSales[[#Headers],[#Data],[% Just the header and the data of
D1:D7
Commission]] % Commission.
The cell at the intersection of the
current row and the Commission
Amount column. If used in the
=DeptSales[[#This Row], [Commission same row as a header or total
Amount]] row, this will return a #VALUE! E5 (if the
error. current
or
row is 5)
=DeptSales[@Commission Amount] If you type the longer form of
this structured reference (#This
Row) in a table with multiple
rows of data, Excel automatically
Which i s
This structured reference: Refers to: cell
range:
replaces it with the shorter form
(@). They both work the same.

Strategies for working with structured


references
Consider the following when you work with structured references.

 Use Formula AutoComplete You may find that using Formula AutoComplete is very
useful when you enter structured references and to ensure the use of correct syntax.
For more information, see Use Formula AutoComplete.
 Decide whether to generate structured references for tables in semi-selection By
default, when you create a formula, clicking a cell range within table semi-selects the
cells and automatically enters a structured reference, instead of the cell range in the
formula. This semi-selection behavior makes it much easier to enter a structured
reference. You can turn this behavior on or off by selecting or clearing the Use table
names in formulas check box in the Working with formulas section of the Formulas
category in the Excel Options dialog box.
 Use workbooks with external links to Excel tables in other workbooks If a workbook
contains an external link to an Excel table in another workbook, that linked "source"
workbook must be open in Excel to avoid #REF! errors in the "destination" workbook
that contains the links. If you open the destination workbook first and #REF! errors
appear, they will be resolved if you then open the source workbook. If you open the
source workbook first, you should see no error codes.
 Convert a range to a table and a table to a range When you convert a table to a
range, all cell references change to their equivalent absolute A1 style references.
When you convert a range to a table, Excel doesn’t automatically change any cell
references of this range to their equivalent structured references.
 Turn off column headers If you turn off table column headers (On the table Design
tab, in the Table Style Options group, clear Header Row), structured references that
use column names aren’t affected, and you can still use them in formulas. Structured
references that refer directly to the table headers (e.g.
=DeptSales[[#Headers],[%Commission]]) will result in #REF.
 Add or delete columns and rows to the table Because table data ranges often
change, the cell references for structured references adjust automatically. For
example, if you use a table name in a formula to count all the data cells in a table, and
you then add a row of data, the cell reference automatically adjusts.
 Rename a table or column If you rename a column or table, Excel automatically
changes the use of that table and column header in all structured references that are
used in the workbook.
 Move, copy, and fill structured references All structured references remain the same
when you copy or move a formula that uses a structured reference.

Note Copying a structured reference and doing a fill of a structured reference are
not the same thing. When you copy, all the structured references remain the same,
while when you fill a formula, fully qualified structured references adjust the column
specifiers like a series as summarized in the following table.

If the fill And while filling,


Then:
direction is: you press:
Up or down Nothing There is no column specifier adjustment.
Up or down Ctrl Column specifiers adjust like a series.
Right or left None Column specifiers adjust like a series.
Up, down, Instead of overwriting values in current cells, current cell
Shift
right, or left values are moved and column specifiers are inserted.
Applies To: Excel 2013

You might also like