From the Not Just Numbers blog:
Although it is worth noting the dangers of hiding rows (see this earlier post for a particularly embarrassing example), they can be useful. If you do use them, you may want any totals on the sheet to exclude the hidden rows, so that the data presented is consistent (i.e. so the total is the total of the numbers you can see).
Fortunately, Excel provides a useful tool for this.
Normally we use the SUM command to add the values in a range, so if we wish to add up column A, rows 1 to 100, then we would use:
This is great, unless we hide row 30 for some very good reason!
If someone was to manually check your sum, they would find that the total wasn’t correct (given the numbers they could see that it was supposed to be adding up). This is because the SUM command will include the hidden row.
We can, however, use a different command to do this that will exclude the hidden row. This command is SUBTOTAL.
will do the same as the SUM command above, but ignore the hidden rows in the total.
I know you’re thinking “Where did that 109 come from?” (like many a Battle of Britain Spitfire pilot!)
Well in this case it’s not the Luftwaffe, but part of the workings of the SUBTOTAL function.
This first argument can be one of 22 numbers in the ranges, 1 to 11 and 101 to 111.
The numbers 1 to 11 cause the function to mimic the following Excel functions:
would work almost identically to our SUM function, except for the following two subtle differences:
- It will exclude rows hidden by Autofilter
- It will also exclude any other SUBTOTALs in the range
If you enjoyed this post, go to the top of the blog, where you can subscribe for regular updates and get two freebies “The 5 Excel features that you NEED to know” and “30 Chants for Better Charts”.