|
|
|
This page presents how to work with Microsoft Excel 2007 features and its redesigned interface. You may also visit our Excel Question page.
|
Count cells that contain numbers
Let's say you want to count only rows that contain numbers and dates in a column that contains a mix of different data types. There are several ways to count cells that contain numbers.
What do you want to do?

Count cells that contain numbers in a contiguous row or column
Count cells that contain numbers that are not in a contiguous row or column

Count cells that contain numbers in a contiguous row or column
- Select a cell below or to the right of the numbers that you want to count.
- On the Home tab, in the Editing group, click the arrow next to AutoSum
, click Count Numbers, and then press ENTER.
Top of Page
Count cells that contain numbers that are not in a contiguous row or column
To do this task, use the COUNT function.
Example
The example may be easier to understand if you copy it to a blank worksheet.
How to copy an example
- Create a blank workbook or worksheet.
- Select the example in the Help topic.
Note Do not select the row or column headers.

Selecting an example from Help
- Press CTRL+C.
- In the worksheet, select cell A1, and press CTRL+V.
- To switch between viewing the results and viewing the formulas that return the results, press CTRL+` (grave accent), or on the Formulas tab, in the Formula Auditing group, click the Show Formulas button.
|
|
|
A
|
|
|
Data
|
|
Sales
|
|
12/8/2007
|
|
|
|
19
|
|
22.44
|
|
Formula
|
Description (Result)
|
|
=COUNT(A2:A6)
|
Counts number of cells that contain numbers (3) in the list. A date is a number.
|
|
=COUNT(A2:A3,A6)
|
Counts number of cells that contain numbers (2), of the top two and bottom cells in the list. A date is a number.
|
|
Function details
COUNT
Top of Page
Excel > Formula and name basics > Examples of formulas > Counting
Count nonblank cells
Excel 2007
Let's say you want to find out how many people entered project hours this week or how many products sold on a specific day. To count nonblank cells, use the COUNTA function.
Example
The example may be easier to understand if you copy it to a blank worksheet.
How to copy an example
- Create a blank workbook or worksheet.
- Select the example in the Help topic.
Note Do not select the row or column headers.

Selecting an example from Help
- Press CTRL+C.
- In the worksheet, select cell A1, and press CTRL+V.
- To switch between viewing the results and viewing the formulas that return the results, press CTRL+` (grave accent), or on the Formulas tab, in the Formula Auditing group, click the Show Formulas button.
|
|
|
A
|
|
|
Data
|
|
Sales
|
|
|
|
19
|
|
TRUE
|
|
|
|
Formula
|
Description (Result)
|
|
=COUNTA(A2:A6)
|
Counts the number of nonblank cells in the list above (3)
|
|
=COUNTA(A2:A3, A6)
|
Counts the number of nonblank cells in the top two, and bottom cell in the list (1)
|
|
Function details
COUNTA
Excel > Formula and name basics > Examples of formulas > Counting
Count how often a value occurs
Excel 2007
Let's say you want to find out how many times particular text or a number value occurs. For example:
- If a range contains the number values 5, 6, 7, and 6, then the number 6 occurs two times.
- If a column contains "Buchanan", "Dodsworth", "Dodsworth", and "Dodsworth", then "Dodsworth" occurs three times.
There are several ways to count how often a value occurs.
What do you want to do?

Count how often a single value occurs by using a function
Count how often multiple number values occur by using functions
Count how often multiple text or number values occur by using functions
Count how often multiple values occur by using a PivotTable report

Count how often a single value occurs by using a function
Use the COUNTIF function to perform this task.
Example
The example may be easier to understand if you copy it to a blank worksheet.
How to copy an example
- Create a blank workbook or worksheet.
- Select the example in the Help topic.
Note Do not select the row or column headers.

Selecting an example from Help
- Press CTRL+C.
- In the worksheet, select cell A1, and press CTRL+V.
- To switch between viewing the results and viewing the formulas that return the results, press CTRL+` (grave accent), or on the Formulas tab, in the Formula Auditing group, click the Show Formulas button.
|
|
|
A
|
B
|
|
Salesperson
|
Invoice
|
|
Buchanan
|
15,000
|
|
Buchanan
|
9,000
|
|
Suyama
|
8,000
|
|
Suyama
|
20,000
|
|
Buchanan
|
5,000
|
|
Dodsworth
|
22,500
|
|
Formula
|
Description (Result)
|
|
=COUNTIF(A2:A7,"Buchanan")
|
Number of entries for Buchanan (3)
|
|
=COUNTIF(A2:A7,A4)
|
Number of entries for Suyama (2)
|
|
=COUNTIF(B2:B7,"< 20000")
|
Number of invoice values less than 20,000 (4)
|
|
=COUNTIF(B2:B7,">="&B5)
|
Number of invoice values greater than or equal to 20,000 (2)
|
|
Function details
COUNTIF
Top of Page
Count how often multiple number values occur by using functions
Let's say you need to determine how many salespeople sold a particular item in a certain region, or you want to know how many sales over a certain value were made by a particular salesperson. You can use the IF and COUNT functions.
Example
The example may be easier to understand if you copy it to a blank worksheet.
How to copy an example
- Create a blank workbook or worksheet.
- Select the example in the Help topic.
Note Do not select the row or column headers.

Selecting an example from Help
- Press CTRL+C.
- In the worksheet, select cell A1, and press CTRL+V.
- To switch between viewing the results and viewing the formulas that return the results, press CTRL+` (grave accent), or on the Formulas tab, in the Formula Auditing group, click the Show Formulas button.
|
|
|
A
|
B
|
C
|
D
|
|
Region
|
Salesperson
|
Type
|
Sales
|
|
South
|
Buchanan
|
Beverages
|
3571
|
|
West
|
Davolio
|
Dairy
|
3338
|
|
East
|
Suyama
|
Beverages
|
5122
|
|
North
|
Suyama
|
Dairy
|
6239
|
|
South
|
Dodsworth
|
Produce
|
8677
|
|
South
|
Davolio
|
Meat
|
450
|
|
South
|
Davolio
|
Meat
|
7673
|
|
East
|
Suyama
|
Produce
|
664
|
|
North
|
Davolio
|
Produce
|
1500
|
|
South
|
Dodsworth
|
Meat
|
6596
|
|
Formula
|
Description (result)
|
|
|
|
=COUNT(IF((A2:A11="South")*(C2:C11="Meat"),D2:D11))
|
Number of salespeople who sold meat in the South region (3)
|
|
|
|
=COUNT(IF((B2:B11="Suyama")*(D2:D11>=1000),D2:D11))
|
Number of sales greater than 1000 by Suyama (2)
|
|
|
|
Notes
Function details
COUNT
IF
Top of Page
Count how often multiple text or number values occur by using functions
Use the IF and SUM functions to do this task:
- Assign a value of 1 to each true condition by using the IF function.
- Add the total, by using the SUM function.
Example
The example may be easier to understand if you copy it to a blank worksheet.
How to copy an example
- Create a blank workbook or worksheet.
- Select the example in the Help topic.
Note Do not select the row or column headers.

Selecting an example from Help
- Press CTRL+C.
- In the worksheet, select cell A1, and press CTRL+V.
- To switch between viewing the results and viewing the formulas that return the results, press CTRL+` (grave accent), or on the Formulas tab, in the Formula Auditing group, click the Show Formulas button.
|
|
|
A
|
B
|
|
Salesperson
|
Invoice
|
|
Buchanan
|
15,000
|
|
Buchanan
|
9,000
|
|
Suyama
|
8,000
|
|
Suyama
|
20,000
|
|
Buchanan
|
5,000
|
|
Dodsworth
|
22,500
|
|
Formula
|
Description (Result)
|
|
=SUM(IF((A2:A7="Buchanan")+(A2:A7="Dodsworth"),1,0))
|
Number of invoices for Buchanan or Dodsworth (4)
|
|
=SUM(IF((B2:B7<9000)+(B2:B7>19000),1,0))
|
Number of invoices with values less than 9000 or greater than 19000 (4)
|
|
=SUM(IF(A2:A7="Buchanan",IF(B2:B7<9000,1,0)))
|
Number of invoices for Buchanan with a value less than 9,000. (1)
|
|
Note The formulas in this example must be entered as array formulas (array formula: A formula that performs multiple calculations on one or more sets of values, and then returns either a single result or multiple results. Array formulas are enclosed between braces { } and are entered by pressing CTRL+SHIFT+ENTER.). Select each cell that contains a formula, press F2, and then press CTRL+SHIFT+ENTER.
Function details
IF
SUM
Top of Page
Count how often multiple values occur by using a PivotTable report
You can use a PivotTable report to display totals and to count the occurrences of unique values.
- Select the column that contains the data. Make sure that the column has a column heading.
- On the Insert tab, in the Tables group, click PivotTable.
- The Create PivotTable dialog box is displayed.
- Click Select a table or range.
- Place the PivotTable report in a new worksheet starting at cell A1 by clicking New Worksheet.
- Click OK.
An empty PivotTable report is added to the location that you specified with the PivotTable field list displayed.
- In the field section at the top of the PivotTable field list, click and hold the field name, and then drag the field to the Row Labels box in the layout section at the bottom of the PivotTable field list.
- In the field section at the top of the PivotTable field list, click and hold the same field name, and then drag the field again to the Values box in the layout section at the bottom of the PivotTable Field List.
Note If your data contains numbers, the PivotTable report totals the entries instead of counting them. To change from the Sum summary function to the Count summary function, select a cell in that column, and then on the Options tab in the Active Field group, click Field Settings, click the Summarize by tab, click Count, and then click OK.
Top of Page
Excel > Formula and name basics > Examples of formulas > Counting
Count unique values among duplicates
Excel 2007
Let's say you want to find out how many unique values exist in a range that contains duplicate values. For example, if a column contains:
- The values 5, 6, 7, and 6, then the result is three unique values—5 , 6 and 7.
- The values "Buchanan", "Dodsworth", "Dodsworth", "Dodsworth", then the result is two unique values—"Buchanan" and "Dodsworth".
There are several ways to count unique values among duplicates.
What do you want to do?

Count the number of unique values by using a filter
Count the number of unique values by using functions

Count the number of unique values by using a filter
You can use the Advanced Filter dialog box to extract the unique values from a column of data and paste them to a new location. Then you can use the ROWS function to count the number of items in the new range.
- Select the range of cells, or make sure the active cell is in a table.
Make sure the range of cells has a column heading.
- On the Data tab, in the Sort & Filter group, click Advanced.
The Advanced Filter dialog box is displayed.
- Click Copy to another location.
- In the Copy to box, enter a cell reference.
Alternatively, click Collapse Dialog
to temporarily hide the dialog box, select a cell on the worksheet, and then press Expand Dialog
.
- Select the Unique records only check box, and click OK.
The unique values from the selected range are copied to the new location beginning with the cell you specified in the Copy to box.
- In the blank cell below the last cell in the range, enter the ROWS function. Use the range of unique values that you just copied as the argument, excluding the column heading. For example, if the range of unique values is B2:B45, then enter:
=ROWS(B2:B45)
Top of Page
Count the number of unique values by using functions
Use the IF, SUM, FREQUENCY, MATCH, and LEN functions to do this task:
- Assign a value of 1 to each true condition by using the IF function.
- Add the total by using the SUM function.
- Count the number of unique values by using the FREQUENCY function. The FREQUENCY function ignores text and zero values. For the first occurrence of a specific value, this function returns a number equal to the number of occurrences of that value. For each occurrence of that same value after the first, this function returns a zero.
- Return the position of a text value in a range by using the MATCH function. This value returned is then used as an argument to the FREQUENCY function so that the corresponding text values can be evaluated.
- Find blank cells by using the LEN function. Blank cells have a length of 0.
Example
The example may be easier to understand if you copy it to a blank worksheet.
How to copy an example
- Create a blank workbook or worksheet.
- Select the example in the Help topic.
Note Do not select the row or column headers.

Selecting an example from Help
- Press CTRL+C.
- In the worksheet, select cell A1, and press CTRL+V.
- To switch between viewing the results and viewing the formulas that return the results, press CTRL+` (grave accent), or on the Formulas tab, in the Formula Auditing group, click the Show Formulas button.
|
|
|
A
|
B
|
|
Data
|
Data
|
|
986
|
Buchanan
|
|
Dodsworth
|
563
|
|
67
|
789
|
|
|
235
|
|
Buchanan
|
Dodsworth
|
|
689
|
789
|
|
Dodsworth
|
143
|
|
56
|
237
|
|
67
|
235
|
|
Formula
|
Description (Result)
|
|
=SUM(IF(FREQUENCY(A2:A10,A2:A10)>0,1))
|
Count the number of unique number values in cells A2:A10, but do not count blank cells or text values (4)
|
|
=SUM(IF(FREQUENCY(MATCH(B2:B10,B2:B10,0),MATCH(B2:B10,B2:B10,0))>0,1))
|
Count the number of unique text and number values in cells B2:B10 (which must not contain blank cells) (7)
|
|
=SUM(IF(FREQUENCY(IF(LEN(A2:A10)>0,MATCH(A2:A10,A2:A10,0),""), IF(LEN(A2:A10)>0,MATCH(A2:A10,A2:A10,0),""))>0,1))
|
Count the number of unique text and number values in cells A2:A10 , but do not count blank cells or text values (6)
|
|
Notes
Function details
FREQUENCY
MATCH
LEN, LENB
SUM
IF
Top of Page
Excel > Formula and name basics > Examples of formulas > Counting
Count numbers greater than or less than a number
Excel 2007
Let's say you want to count how many salespeople exceeded their sales goals for a quarter or how many stores under-performed compared to an industry average for yearly revenues. To count numbers greater than or less than a number, use the COUNTIF function.
Example
The example may be easier to understand if you copy it to a blank worksheet.
How to copy an example
- Create a blank workbook or worksheet.
- Select the example in the Help topic.
Note Do not select the row or column headers.

Selecting an example from Help
- Press CTRL+C.
- In the worksheet, select cell A1, and press CTRL+V.
- To switch between viewing the results and viewing the formulas that return the results, press CTRL+` (grave accent), or on the Formulas tab, in the Formula Auditing group, click the Show Formulas button.
|
|
|
A
|
B
|
|
Salesperson
|
Invoice
|
|
Buchanan
|
15,000
|
|
Buchanan
|
9,000
|
|
Suyama
|
8,000
|
|
Suyama
|
20,000
|
|
Buchanan
|
5,000
|
|
Dodsworth
|
22,500
|
|
Formula
|
Description (Result)
|
|
=COUNTIF(B2:B7,">9000")
|
Numbers above 9000 (3)
|
|
=COUNTIF(B2:B7,"<=9000")
|
Numbers less than or equal to 9000 (3)
|
|
Function details
COUNTIF
Excel > Formula and name basics > Examples of formulas > Counting
Count all of the cells in a range
Excel 2007
Let's say you want to determine the size of a large spreadsheet to decide whether to use manual or automatic calculation in your workbook. To count all of the cells in a range, use a formula that multiplies the return values from the ROWS and COLUMNS functions.
Example
The example may be easier to understand if you copy it to a blank worksheet.
How to copy an example
- Create a blank workbook or worksheet.
- Select the example in the Help topic.
Note Do not select the row or column headers.

Selecting an example from Help
- Press CTRL+C.
- In the worksheet, select cell A1, and press CTRL+V.
- To switch between viewing the results and viewing the formulas that return the results, press CTRL+` (grave accent), or on the Formulas tab, in the Formula Auditing group, click the Show Formulas button.
|
|
|
A
|
B
|
C
|
D
|
|
Data
|
Data
|
Data
|
Data
|
|
15,000
|
28,500
|
55,000
|
87,000
|
|
9,000
|
13.700
|
63,800
|
23,000
|
|
8,000
|
1000
|
19,000
|
99,900
|
|
Formula
|
Description (Result)
|
|
|
|
=ROWS(A1:D4) * COLUMNS(A1:D4)
|
The total number of cells in the range (16)
|
|
|
|
Function details
ROWS
COLUMNS
Excel > Formula and name basics > Examples of formulas > Counting
Count the number of words in a cell or range
Excel 2007
Let's say you want to find out how many words are used in a cell or cell range that contains a long string of text, such as a description or comment field. There are several ways to do this task.
What do you want to do?

Count the number of words in a cell
Count the number of words in a range of cells

Count the number of words in a cell
To do this task, use the LEN, TRIM, and SUBSTITUTE functions.
Example
The example may be easier to understand if you copy it to a blank worksheet.
How to copy an example
- Create a blank workbook or worksheet.
- Select the example in the Help topic.
Note Do not select the row or column headers.

- Press CTRL+C.
- On the worksheet, select cell A1, and then press CTRL+V.
- To switch between viewing the results and viewing the formulas that return the results, press CTRL+` (grave accent), or on the Formulas tab, in the Formula Auditing group, click the Show Formulas button.
In this example, cell A1 contains the text "Have a nice day!", and cell A2 contains the formula. The formula returns a value of 4 to reflect that the cell contains four words separated by spaces. It makes no difference if words are separated by multiple spaces or if words start or end with a space. The TRIM function removes extra spaces, starting spaces, and ending spaces in the text of the cell.
|
|
|
A
|
|
Have a nice day!
|
|
Formula
|
Description (Result)
|
|
=IF(LEN(TRIM(A1))=0,0,LEN(TRIM(A1))-LEN(SUBSTITUTE(A1," ",""))+1)
|
Counts the words in A1 (4)
|
|
Note To avoid a circular reference, make sure that you enter the formula in a cell outside of the cell for which you are counting the words. Also make sure that you change the cell references in the formula to reflect the cell that contains the words that you want to count.
Function details
LEN, LENB
TRIM
SUBSTITUTE
Top of Page
Count the number of words in a range of cells
To do this task, use the SUMIF, LEN, TRIM, and SUBSTITUTE functions in an array formula.
Example
The example may be easier to understand if you copy it to a blank worksheet.
How to copy an example
- Create a blank workbook or worksheet.
- Select the example in the Help topic.
Note Do not select the row or column headers.

- Press CTRL+C.
- On the worksheet, select cell A1, and then press CTRL+V.
- To switch between viewing the results and viewing the formulas that return the results, press CTRL+` (grave accent), or on the Formulas tab, in the Formula Auditing group, click the Show Formulas button.
In this example, the formula returns a value of 37 to reflect that the range contains thirty-seven words separated by spaces. It makes no difference if words are separated by multiple spaces or if words start or end with a space. The TRIM function removes extra spaces, starting spaces, and ending spaces in the text of the cell. To get the total number of words in the specified range, the array formula counts the words in each cell of that range, and the SUM function then adds up the values for each cell to get the total.
|
|
|
A
|
B
|
C
|
D
|
|
Eat more vegetables!
|
Smell the roses.
|
A day without rain...
|
The bells!
|
|
Friday
|
Saturday
|
Sunday
|
Monday
|
|
Take Mom to dinner
|
Wash the dog
|
Walkathon
|
Job interview
|
|
Never surrender!
|
Make it a great day!
|
Press on!
|
Ever onward!
|
|
Formula
|
Description (Result)
|
|
=SUM(IF(LEN(TRIM(A1:D4))=0,0,LEN(TRIM(A1:D4))-LEN(SUBSTITUTE(A1:D4," ",""))+1))
|
Counts the words in the cell range A1:D4 (37)
|
|
Notes
- To avoid a circular reference, make sure that you enter the formula in a cell outside of the range for which you are counting the words. Make sure that you change the range references in the formula to reflect the range of cells that contain the words that you want to count.
- To enter an array formula, select the cell that contains the formula, press F2, and then press CTRL+SHIFT+ENTER.
Tip To see a function evaluated step by step, select the cell that contains the formula. On the Formulas tab, in the Formula Auditing group, click Evaluate Formula.
Function details
SUMIF
LEN, LENB
TRIM
SUBSTITUTE
Top of Page
See Also
Excel > Formula and name basics > Examples of formulas > Counting
Calculate a running total
Excel 2007
Let's say you want to see the number of products in an inventory list grow as you add products each day. Use a running total (also called a running count) to watch the number of items in a spreadsheet add up as you enter new items. To calculate a running total, use the following procedure.
- Set up a worksheet like the following example.
Example
The example may be easier to understand if you copy it to a blank worksheet.
How to copy an example
- Create a blank workbook or worksheet.
- Select the example in the Help topic.
Note Do not select the row or column headers.

Selecting an example from Help
- Press CTRL+C.
- In the worksheet, select cell A1, and press CTRL+V.
- To switch between viewing the results and viewing the formulas that return the results, press CTRL+` (grave accent), or on the Formulas tab, in the Formula Auditing group, click the Show Formulas button.
|
|
|
A
|
B
|
C
|
|
Product
|
Description
|
Running total
|
|
Sandbox
|
Sturdy but a bit worn
|
1
|
|
Beach toys
|
Hardly used
|
=1+C2
|
|
Swing set
|
Weathered, but still safe
|
=1+C3
|
|
- Click anywhere outside cell C4 to see the running total.
- To maintain the running total, add a row for each new entry by doing the following:
- Type the product and description into the empty rows directly below the existing data.
For instance, if you were using the example above, you would type the products into A5, A6, and so on, and the descriptions into B5, B6, and so on.
- Extend the running total formula into the new rows by selecting the last cell in the balance column and then double-clicking the fill handle (fill handle: The small black square in the lower-right corner of the selection. When you point to the fill handle, the pointer changes to a black cross.).
For instance, if you were using the example above, you would select cell C3 and then double-click its fill handle to extend the formula into all new rows that contain products and descriptions.
Note A running total differs from a running balance, in which you watch the sum of values grow as new entries are added. For more information, see Calculate a running balance.