In this example, the goal is to count rows that are visible and ignore rows that are hidden. This is a job for the SUBTOTAL function. SUBTOTAL can perform a variety of calculations like COUNT, SUM, MAX, MIN, and more. What makes SUBTOTAL interesting and useful is that it automatically ignores items that are not visible in a filtered list or table. This makes it ideal for running calculations on the rows that are visible in filtered data.
Count with SUBTOTAL
Following the example in the worksheet above, to count the number of non-blank rows visible when a filter is active, use a formula like this:
The first argument, function_num, specifies count as the operation to be performed. SUBTOTAL ignores the 3 rows hidden by the filter and returns 7 as a result, since there are 7 rows visible.
Note that SUBTOTAL always ignores values in cells that are hidden with a filter. Values in rows that have been "filtered out" are never included, regardless of function_num. If you are hiding rows manually (i.e. right-click > Hide), and not using filter controls , use this version of the formula instead:
With the function_num set to 103, SUBTOTAL still performs a count, but this time it will ignore rows that are manually hidden, as well as those hidden with a filter. To be clear, values in rows that have been hidden with a filter are never included, regardless of function_num.
The SUBTOTAL function can perform many other calculations. To see a list of all the calculations SUBTOTAL can perform, see this page.