You are on page 1of 32

Examples to count values in a spreadsheet

The following worksheets have various examples to count values in a spreadsheet. Refer to the following Suppor

Ways to count values in a spreadsheet

Worksheet
Count numbers with AutoSum
Add subtotals
SUBTOTAL function
COUNT function
COUNTIF function
DCOUNT function
COUNTIFS function
COUNT nested with IF
SUM nested with IF
PivotTable
COUNTA function
DCOUNTA function
COUNTBLANK function
SUM, IF, MATCH, LEN and FREQUENCY
ROWS and COLUMNS functions
SUM, LEN, TRIM and SUBSTITUTE

• Cells highlighted like this are for user input. Click on the cell for further information.
ount values in a spreadsheet
ve various examples to count values in a spreadsheet. Refer to the following Support.Office.com article

What you will find


Use the AutoSum wizard to count values in a contiguous range.
Add a subtotal row in Excel data
Use the SUBTOTAL function to count cells in a column in a list or table
Use the COUNT function to find the number of cells containing numeric values in a range
Use the COUNTIF function function to count how many times a particular value appears in a range of cells.
Use the DCOUNT function to counts the cells that contain numbers in a field (column) of records in a list or database that m
Use the COUNTIFS function lets you apply criteria to cells across multiple ranges and counts the number of times all criteria
Use COUNT along with IF to count based on criteria.
Use SUM along with IF to count based on criteria.
Count a particular value in a column or a row in a PivotTable
Use the COUNTA function to count only cells in a range that contains values.
Use the DCOUNTA function to count nonblank cells in a column of records in a list or database that match conditions that
Use the COUNTBLANK function function to return the number of blank cells in a contiguous range.
Use a nested formula with SUM, IF, MATCH, LEN and FREQUENCY functions to count the number of unique values in a ran
Use the ROWS and COLUMNS functions to count the total number of cells in a range.
Use a nested formula with SUM, LEN, TRIM, and SUBSTITITE functions to count the number of words in a range.

are for user input. Click on the cell for further information.
Use the AutoSum Wizard
Example
Hours Hours
worked worked
Name (week 1) (week 2)
Bob 8 2
Rishna 4
Sue 8 8
Mo 5 4
Total number of entries logged 4

Select cells from B5:B8, and then go to


See more online: SUM function Formulas > AutoSum > Count Numbers.
--OR--
Select B9 and press ALT + Enter.

Excel will display the total count of cells for


the selected range in B9.
Add subtotals
In the following example, you can add subtotal rows to the Golf and Tennis sales. NOTE: Subtotals aren't s
Sport Quarter Sales tables. If you need subto
use a PivotTable.
Golf Qtr 3 1500
Golf Qtr 4 2000
Golf Qtr 3 6430 Click inside any cell in C5:C11 range, and then click
Data > Subtotal > OK.
Tennis Qtr 3 600
Tennis Qtr 4 1500 Excel displays the subtotals for Golf and Tennis in
separate rows, and the Grand Total (the sum of both
Tennis Qtr 3 4700 subtotals) in the last row.
Tennis Qtr 4 3250

See online: Insert subtotals in a list of data in a worksheet


NOTE: Subtotals aren't supported in Excel
tables. If you need subtotals from table data,
use a PivotTable.
Count cells in a list or table column using SUBTOTAL
The 2 in the syntax specifies that
Example 1 SUBTOTAL should use the COUNT
function to return the count of values
Sport Quarter Sales in C7:C14 range.
Golf Qtr 1 4200
Golf Qtr 2 3245
Golf Qtr 3 1500 Formula =SUBTOTAL(2,C5:C12)
Golf Qtr 4 2000 Output 8
Tennis Qtr 1 600
Tennis Qtr 2 1500
Tennis Qtr 3 4700
Tennis Qtr 4 5000
TOTAL 22745

Example 2 In Example 2, four r


Sport Quarter Sales hidden. SUBTOTAL
rows and returns th
Golf Qtr 1 4200 Formula =SUBTOTAL(2,C17:C24) cells in the range 8
Golf Qtr 2 3245 Output 8
For SUBTOTAL to ex
Golf Qtr 3 1500 a range, set the fun
Golf Qtr 4 2000 to 102. Try it!
TOTAL 10945

The error indicator


simply lets you know
that the hidden cells in
the range are not
included in the formula.

See more online: SUBTOTAL function


Total the data in an Excel table
fies that
e COUNT
ount of values

In Example 2, four rows for Tennis are


hidden. SUBTOTAL detects the hidden
rows and returns the actual number of
cells in the range 8.

For SUBTOTAL to exclude hidden items in


a range, set the function_num argument
to 102. Try it!
Count cells in a range using COUNT
Sample Data
5
32
Hello
World
5/27/2016
9:00 a.m
Enter numerical values in the
highlighted cells and watch the
Output change.

Formula =COUNT(A4:A12)
Output 3

See more online: COUNT function


Count cells in a range based on a single condition with COUNT
Salesperson Invoice
Buchanan 15000
Buchanan 9000
Suyama 8000
Suyama 20000
Buchanan 5000
Dodsworth 22500

When formula is Description Output

=COUNTIF(A4:A9,"Buchanan") Number of entries for 3


Buchanan

=COUNTIF(A4:A9,A6) Number of entries for 2


Suyama

=COUNTIF(B4:B9,"< 20000") 4
Number of invoice
values less than 20,000

Number of invoice
=COUNTIF(B4:B9,">="&B7) 2
values greater than or
equal to 20,000

Number of invoice
#N/A values greater than
4000 and lesser than
15000

Refer to the description in B15


and create the appropriate
formula in this highlighted cell.

See more online: COUNTIF function


with COUNTIF
Count cells in a column based on single or multiple conditions
Sales in units Month ending
339 1/31/2016
270 2/29/2016
314 3/31/2016
422 4/30/2016
336 5/31/206
405 6/30/2016

Sales in units Month ending


>400 >=3/31/2016

Formula =DCOUNT(A3:B9,"Month ending",A11:B12)


Output 2

See more online: DCOUNT function


e conditions with DCOUNT
Count cells in a range based on multiple conditions with COUN
Employee ID Department Region No.
20552 Sales 2
21268 Finance 2
23949 Operations 1
24522 Operations 4
28010 IT 3
29546 Sales 4
31634 IT 3
32131 Human Resources 1
35106 Finance 4
40499 IT 2
42051 Human Resources 1
43068 Finance 3
45382 IT 3
47971 Finance 2

Formula Output
=COUNTIFS(C4:C17, "2",B4:B17, "Finance") 2

See more online: COUNTIFS function


ions with COUNTIFS
Count based on criteria by using the COUNT and IF functions to
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 {=COUNT(IF((A4:A13="South")*(C4:C13="Meat"),D4:D13))}
Description Number of sales of meat in the South region.
Output 3

Formula {=COUNT(IF((B4:B13="Suyama")*(D4:D13>=1000),D4:D13))}
Description Number of sales greater than $1,000 by Suyama.
Output 2

See more online: IF function- nested formulas and avoiding pitfalls


nd IF functions together
Count how often multiple text or number values occur by using
Salesperson Invoice
Buchanan 15000
Buchanan 9000
Suyama 8000
Suyama 20000
Buchanan 5000
Dodsworth 22500

No. of invoices for Click on this cell to see the formula


in the Formula bar. The curly braces
Buchanan or indicate that this is an array formula.
Dodsworth 4

See more online: IF function- nested formulas and avoiding pitfalls


s occur by using the SUM and IF functions together
Sport Quarter Sales
Golf Qtr 3 $1,500
Golf Qtr 4 $2,000 To create a PivotTable, follow these steps:
Tennis Qtr 3 $600 1) Select A1:C8.
2) Click Insert > PivotTable.
Tennis Qtr 4 $1,500 3) In the Create PivotTable dialog box, click Select a table
Tennis Qtr 3 $4,070 or range > New Worksheet > OK.
4) In the PivotTable Fields pane, do the following:
Tennis Qtr 4 $5,000 a. Drag Sport to the Rows area.
Golf Qtr 3 $6,430 b. Drag Quarter to the Columns area.
c. Drag Sales to the Values area.
d. Repeat step c.
The field name displays as SumofSales2 in both the
PivotTable and the Values area.
e. In the Values area, click the dropdown next to
SumofSales2 and select Value Field Settings.
f. In the Value Field Settings dialog box, do the following:

i. In the Summarize value field by section, select Count.


ii. In the Custom Name field, modify the name to Count.
The field name displays as SumofSales2 in both the
PivotTable and the Values area.
iii. Click OK.
See more online: Ways to count values in a spreadsheet
Count nonblank cells in a range by using the COUNTA function
Region Salesperson Type Sales
South Buchanan Beverages 3571
West Davolio Dairy
East Suyama Beverages 5122
North Suyama Dairy
South Dodsworth Produce 8677
South Davolio Meat 450
South Davolio Meat
East Suyama Produce 664
North Davolio Produce 1500
South Dodsworth Meat

Formula =COUNTA(D4:D13)
Output 6

See more online: COUNTA function


OUNTA function
Count nonblank cells in a list with specific conditions by using
Product ID Ratings
2048 61
16384
35336 83
1024 113
512
976 47

Product ID Ratings
>=2000 >=50

Formula =DCOUNTA(A3:B9,"Ratings",A11:B12)
Ouput 2

See more online: DCOUNTA function


ditions by using the DCOUNTA function
Count blank cells in a contiguous range by using the COUNTBL
Location Location ID Highest-selling fruit Sales
Bellevue 1102345AW Apples $2,475.87
Redmond 1102345AK Apples $2,895.90
Bellevue 1102345AW Strawberries
Kirkland 1102345AP Oranges
Redmond 1102345AK Strawberries $3,487.73
Kirkland 1102345AP Strawberries

Formula =COUNTBLANK(A4:D9)
Output 3

See more online: COUNTBLANK function


g the COUNTBLANK function
Count the number of unique values in a range that meet one o
Dataset 1 Dataset 2
986 Bradley
Doyle 563
67 789
235
Bradley Doyle
689 789
Doyle 143
56 237
67 235

Formula {=SUM(IF(FREQUENCY(A4:A12,A4:A12)>0,1))}
Output 4
that meet one or more conditions by using IF, SUM, FREQUENCY, MA
FREQUENCY, MATCH, and LEN functions
Count the total number of cells in a range by using ROWS and
Employee ID Department Region No.
20552 Sales 2
21268 Finance 2
23949 Operations 1
24522 Operations 4
28010 IT 3
29546 Sales 4
31634 IT 3
32131 Human Resources 1
35106 Finance 4
40499 IT 2
42051 Human Resources 1
43068 Finance 3
45382 IT 3
47971 Finance 2

Formula Output
=ROWS(A4:C17) * COLUMNS(A4:C17) 42
g ROWS and COLUMNS functions
Use a nested formula to count words in a range
Sample data
Two roads diverged in a yellow wood,
And sorry I could not travel both
And be one traveler, long I stood
And looked down one as far as I could
To where it bent in the undergrowth;

Formula
=SUM(IF(LEN(TRIM(A4:A8))=0,0,LEN(TRIM(A4:A8))-LEN(SUBSTITUTE(A4:A8," ",""))+1))
Output
#VALUE!

The #VALUE! error is because the formula is not


entered as an array formula. To do that, click on the
highlighted cell, and then, press Ctrl + Shift + Enter
(also called the key combination). Notice the curly
braces wrapped around the formula. This is now an
array formula!
The formula will now display the value of 37.

You might also like