Google-sheets – Google Spreadsheets sum only shown rows

formulasgoogle sheets

Is it possible to sum a range of cells while ignoring rows which are not hidden?

Best Answer

I'm not sure if you necessarily require a Google Apps Script solution; the tags you have used suggest that a spreadsheet formula might be adequate. If this is the case, then it is definitely possible to achieve this using SUBTOTAL.

For example:

=SUBTOTAL(109,A:A)

will sum all cells in column A that are not hidden. 109 is the function_code which consists of 9 for SUM, prepended with 10 so hidden values will be skipped.

Your question requests that the sum should be "ignoring rows that are not hidden", which, I believe, is equivalent to "sum the hidden rows". This may be achieved using:

=SUM(A:A)-SUBTOTAL(109,A:A)