Use SUBTOTAL with code 109
SUM adds every cell in its range, including rows you have hidden or filtered out. To add only the visible rows, use SUBTOTAL with function number 109:
=SUBTOTAL(109, C2:C200)
If your list has a filter, apply it first by going to Data and choosing Filter. The total then updates as you change the filter.
What the codes mean
SUBTOTAL has two sets of function numbers:
- 1 to 11 include rows you hid by hand.
- 101 to 111 leave out rows you hid by hand as well as filtered rows.
Rows removed by a filter are always left out, whichever code you use. Code 9 is the plain SUM, and it still counts rows hidden by hand. Code 109 is the one to use when you want only what you can see.
A filtered example
Say column A lists regions and column C holds revenue, from row 2 to row 200. Filter column A to show only East. The formula:
=SUBTOTAL(109, C2:C200)
then shows the revenue total for the East rows that are still showing. Place the formula above the list, or in a row the filter won’t hide, so it stays visible too.
Skip nested subtotals
If the list already contains subtotal rows, SUBTOTAL ignores other SUBTOTAL results inside its range. That avoids double counting when you put a grand total below groups of subtotals.
Copy only the visible cells
SUBTOTAL covers the total. To copy only the visible cells, select the range, press Alt and the semicolon key (;) to select just the visible cells, then copy and paste as usual.
An AGGREGATE alternative
AGGREGATE can also sum while skipping hidden rows. Use function 9 for SUM and option 5 to ignore hidden rows:
=AGGREGATE(9, 5, C2:C200)
Option 7 ignores hidden rows and error values together, which helps when a range contains errors such as #N/A.
Limits to know
SUBTOTAL is designed for columns of data. Hiding a column doesn’t change a total across a row of cells, so for horizontal ranges the codes behave differently from what you might expect.
Rules instead of filters
If the rows you want can be described by a rule, SUMIFS may be easier than filtering. Its result doesn’t depend on what’s on screen, so it stays the same however the sheet is filtered. The approach is covered in sumifs with multiple criteria in excel. For a single rule, how to use sumif in excel is the simplest option. FILTER can also pull out matching rows for a total, as described in how to use filter function in excel.