Skip to content

How to sum visible rows only in Excel in Excel

Add only the rows left visible after filtering or hiding, using SUBTOTAL or AGGREGATE instead of SUM.

You filter a list to one region and glance at the total. It is wrong: it still includes the rows you filtered out. SUM adds every cell in the range, visible or not.

SUBTOTAL was built for this. Its first argument is a function number that says what to calculate, and the second is the range:

=SUBTOTAL(109, B2:B10)

109 means SUM, ignoring rows hidden by a filter and rows you hid by hand. The matching numbers for the other calculations are 101 for AVERAGE, 102 for COUNT, 103 for COUNTA, 104 for MAX and 105 for MIN.

The shorter set, 1 to 11, behaves the same for filtered rows but still includes rows you hid manually with Hide. In most work you want the 100-series. SUBTOTAL also skips any other SUBTOTAL formulas inside its range, so a total of subtotals does not count anything twice.

AGGREGATE is the more flexible cousin. With function 9 (sum) and option 5, it ignores hidden rows: =AGGREGATE(9, 5, B2:B10). Option 6 ignores errors, and option 7 ignores both, which makes AGGREGATE useful on data that contains #N/A.

You rarely need to type SUBTOTAL yourself. On the ribbon, put the cursor under a filtered column and choose Formulas > AutoSum (or Home > AutoSum). Excel inserts SUBTOTAL(109,...). In an Excel table, turn on Table Design > Total Row and it uses the same function.

The practice grid on this page has no hidden rows, so it checks that you used SUBTOTAL. Try it in a real workbook with a filter on to see the difference. The Analysis track covers SUBTOTAL and AGGREGATE together.

3 ways to do it

1SUBTOTAL with a 100-series function number

=SUBTOTAL(109,B2:B10)

  1. Type =SUBTOTAL(109,B2:B10) under or beside the list.
  2. Apply a filter with Data > Filter and change the filter. The total follows the visible rows.
  3. Use 101 for average, 102 for count, 104 for max and 105 for min.

2AGGREGATE (can also skip errors)

=AGGREGATE(9,5,B2:B10)

  1. Type =AGGREGATE(9,5,B2:B10). The first number is the function (9 is SUM) and 5 ignores hidden rows.
  2. Use option 6 to ignore errors, or 7 to ignore hidden rows and errors together.

3AutoSum on the ribbon

  1. Filter the list with Data > Filter.
  2. Select the cell under the column and choose Formulas > AutoSum. Excel inserts SUBTOTAL for you.

Try it yourself

Solve it in the sheet. Every answer is checked, with hints if you need them.

Task 1 of 2

In D2, total B2:B10 so that the result ignores rows hidden by a filter.

Answer in D2.

D2
A
B
C
D
E
1
Item
Amount
Visible total
2
Cables
240
3
Adapters
135
4
Batteries
410
Visible average
5
Chargers
320
6
Docks
780
7
Headsets
295
8
Keyboards
560
9
Mice
180
10
Webcams
425
11
12

Learn it properly, one graded sheet at a time.

Excel foundations covers this in lesson 5, SUM and ranges.