Subtotal
Subtotal
See Also: EXCEL SUBTOTALS || Making the SUBTOTAL Function Dynamic || BOLD EXCEL SUBTOTALS
AUTOMATICALLY || SUM EVERY NTH CELL || COUNT OF EACH ITEM IN A LIST || EXCEL PIVOT TABLES
The SUBTOTAL Function in Excel is used to perform a specified function on a range of Auto filtered cells.
When the Auto Filter has been applied the SUBTOTAL function will only use the visible cells, all hidden
rows are ignored. The operation performed is solely dependent on the number (between 1 and 11) that
we supply to it's first argument Function_num For example;
=SUBTOTAL(1,A1:A100)
will Average all visible cell in the range A1:A100 after an Auto Filter has been applied. If all rows in
A1:A100 are visible it will simply Average them all and give the same result as
=AVERAGE(A1:A100)
The number for the first SUBTOTAL argument, Function_num, and it's corresponding function are as
shown below
Function_Num Function
1 AVERAGE
2 COUNT
3 COUNTA
4 MAX
5 MIN
6 PRODUCT
7 STDEV
8 STDEVP
9 SUM
10 VAR
11 VARP
As we only need to use a number between 1 and 11 we can have the one SUBTOTAL function perform a
function of our choice. We can even make the choice from a drop-down list which resides in any cell. Here
is how;
Add all the function names, in the same order as above, to a range of cells. I will use D1:D11
With this range selected, click in the Name Box (white box left of the Formula Bar) and type
the name: Subs and then click Enter.
Select all of Column D and go to Format>Column>Hide
Go to View>Toolbars>Forms and then click on the Combo box Control and click cell C2
Use the Size Handles to size the combo box so it can display the longest function name, i.e
AVERAGE
Right click on the Combo box and choose Format control then the Control tab.
In the Input range: type: Subs In the Cell link: box type:$C$2 Change the Drop down
lines: to 11
In cell C3 Enter this formula: =IF($C$2="","","Result of "&INDEX(Subs,$C$2))
In cell C4 Enter this formula: =IF($C$2="","",SUBTOTAL($C$2,$A$4:$A$100)) Where
$A$4:$A$100 is the range the SUBTOTAL should act on.
Now all you need to do is select the required SUBTOTAL function from the Combo box and the correct
result will be displayed.