Cellwise Start free

Excel guide · 4 min read

How to sum only visible cells in Excel

Quick answerUse =SUBTOTAL(109,E2:E11). It adds only the rows you can see, skipping rows hidden by a filter and rows you hid by hand. SUBTOTAL(9,E2:E11) skips filtered rows but still counts manually hidden ones. Plain SUM always adds every row, hidden or not.

Sample data

Every result on this page was calculated from this sheet by the same spreadsheet engine the Cellwise app uses.

ABCDE
1OrderRegionRepStatusAmount
2SO-2201NorthPriyaShipped1250
3SO-2202SouthTomShipped980
4SO-2203NorthAnaCancelled2400
5SO-2204EastPriyaShipped615
6SO-2205NorthTomShipped1830
7SO-2206SouthAnaPending740
8SO-2207NorthPriyaPending525
9SO-2208EastTomCancelled1100
10SO-2209NorthAnaShipped2075
11SO-2210SouthPriyaShipped1360

Download this sheet as an Excel practice file (.xlsx)

Why SUM includes hidden rows

SUM adds every number in its range. It has no idea whether a row is hidden, filtered out or collapsed in an outline. So when you filter this sales list to the North region and look at a SUM below it, the total does not change: it still shows all ten orders.

That is by design, and sometimes it is what you want, for example a grand total that must not change when someone plays with the filter. When you want the total of what is on screen, you need SUBTOTAL or AGGREGATE.

=SUM(E2:E11)

Result: 12875

12,875: all ten orders, no matter which rows are hidden or filtered.

SUBTOTAL: 9 vs 109

SUBTOTAL's first argument picks the calculation: 9 is SUM, 1 is AVERAGE, 3 is COUNTA, 4 is MAX and so on. Add 100 and you get the same calculation, but it also skips rows you hid by hand. Rows filtered out by a filter are always skipped, whichever number you use.

So =SUBTOTAL(9,E2:E11) changes when you filter for North, but if you also right-click the Cancelled rows and choose Hide, it still adds them. =SUBTOTAL(109,E2:E11) leaves out both. Use 109 unless you have a reason not to, because people hide rows to say "ignore these", and 109 respects that. Both versions also skip other SUBTOTAL formulas inside the range, so subtotal rows within a list are not counted twice.

  1. Filter the list: select a cell in it and press Ctrl+Shift+L, then pick North in the Region drop-down.
  2. Below the Amount column, type =SUBTOTAL(109,E2:E11). The result now changes every time you change the filter or hide rows.
  3. Shortcut: with a filter on, AutoSum (Alt+=) inserts a SUBTOTAL(9,...) formula instead of SUM. Edit the 9 to 109 if you also hide rows by hand.
  4. In an Excel table, Table Design > Total Row adds SUBTOTAL(109,...) for you.

AGGREGATE: visible rows and no errors

SUBTOTAL returns an error if any cell in the range holds one, such as a #N/A from a lookup. AGGREGATE (Excel 2010 and later) works like SUBTOTAL but has an options argument. =AGGREGATE(9,5,E2:E11) sums while ignoring hidden rows; =AGGREGATE(9,7,E2:E11) ignores hidden rows and error values; =AGGREGATE(9,6,E2:E11) ignores only errors.

Options 5 and 7 skip both filtered and manually hidden rows, like SUBTOTAL 109. Pick AGGREGATE when your amounts come from formulas that sometimes fail; otherwise SUBTOTAL is shorter and more widely understood.

Conditional totals that never depend on the filter

The sample sheet on this page cannot hide rows, so it cannot show SUBTOTAL or AGGREGATE results live. What it can show is the other way to get "the North total": state the condition in the formula. SUMIFS adds Amount where Region is North and Status is not Cancelled, the same rows you would see after filtering North and hiding the cancelled orders.

This is often the better choice for a report. A SUBTOTAL total is only right while the filter is set the way you expect, and it silently changes when someone else filters the sheet. A SUMIFS total says in the formula what it counts. Use SUBTOTAL for quick totals while you explore, and SUMIFS for numbers you send to other people.

=SUMIFS(E2:E11,B2:B11,"North",D2:D11,"<>Cancelled")

Result: 5680

5,680: the four North orders that are not cancelled (1,250 + 1,830 + 525 + 2,075).

Sum visible rows that also meet a condition

Sometimes you want both: whatever the user has filtered, plus a condition, such as only Shipped orders among the visible rows. SUMIFS cannot tell whether a row is hidden, and SUBTOTAL has no criteria. The cleanest fix is a helper column: in F2 enter =SUBTOTAL(103,A2) and fill it down. It shows 1 when the row is visible and 0 when it is hidden or filtered out.

Then add the helper as one more condition: =SUMIFS(E2:E11,D2:D11,"Shipped",F2:F11,1). Without a helper column, the one-cell formula is =SUMPRODUCT(SUBTOTAL(109,OFFSET(E2,ROW(E2:E11)-ROW(E2),0))*(D2:D11="Shipped")): OFFSET hands SUBTOTAL one cell at a time, so it returns each visible amount and 0 for hidden ones. It works, but it is hard to read and slow on long lists.

Common mistakes

Using SUBTOTAL(9) and hiding rows by hand

Function number 9 still adds manually hidden rows. Use 109 to skip them too.

Expecting SUBTOTAL to skip hidden columns

SUBTOTAL and AGGREGATE only ignore hidden rows. In a total across a row, hidden columns are still added. Lay the data out in columns, or use SUMIFS with a condition.

Putting the SUBTOTAL total inside the filtered range

A total in a row that the filter can hide disappears with it. Put totals above the header or in a row below the data with an empty row between.

Sending a report whose total depends on the current filter

The next person to change the filter changes the number. Use SUMIFS with the conditions written in, and label what the total includes.

FAQ

How do I sum only filtered cells in Excel?

Use =SUBTOTAL(9,range) or =SUBTOTAL(109,range) below the filtered column. Both skip rows the filter hides; 109 also skips rows hidden by hand. With a filter on, AutoSum inserts SUBTOTAL(9,...) automatically.

What is the difference between SUBTOTAL 9 and 109?

Both sum the range and both ignore rows hidden by a filter. 9 includes rows you hid with Hide or collapsed in an outline; 109 excludes them.

How do I count visible rows only?

Use =SUBTOTAL(103,A2:A11) to count non-empty visible cells, or =SUBTOTAL(102,E2:E11) to count visible numbers. Point it at a column every row fills in.

How do I copy only the visible cells?

Select the range, press Alt+; (or Home > Find & Select > Go To Special > Visible cells only), then copy. Excel copies only the visible cells, so hidden rows do not come along.

Why does my SUBTOTAL show #N/A?

One of the cells in the range holds an error. Fix the source formula, or switch to =AGGREGATE(9,7,range), which ignores hidden rows and errors.

Functions used

Related guides

Updated