# Excel Sub-Totals : Getting the Percentages Calculating Correctly

Patrick O'Dea used Ask the Experts™
on
Hi,

See attached.
This shows sales by customer by country and the change this year VERSUS Last Year.

However, the % figure (in red) is wrong for obvious reasons.

Has Excel any clever way of getting this % figure correct.
I do NOT want to manually enter a new calculation formula if at all possible.

Comment
Watch Question

Do more with

EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Hi, 21Dewsbury.

I don't understand what you're looking for. The formula is incorrect. You want it corrected without changing it?

Regards,
Brian,

Commented:
Hi,

this is a very strange request since the only way of getting the desired result is to use what you want to avoid. Manually inserting the correct formula.

But do not dispare, there is an easy way to do this since you have the formula already in the cell F2, you can just double click on the right bottom corner of that cell (the plus sign) and the formula will be copied down no efforts needed.

Have a nice day and good luck.

Commented:
Hi folks,
Let me clarify matters.
The example I have attached above is a simplified one.

In reality I have over 500 sub totals in this sheet.
I generate the sub-totals by using excels standard sub-total function.  This process takes about 10 seconds!!
However, in column F it is meaningless to sub-total the "% difference".
I guess I require "The % Difference of the Sub-Totals" but I am getting "Sub-Total of the % Differences".

This should not be an odd request as it would arise in very many sheets of financial analysis.

To revert back to my example, I know that the USA spend \$453 more dollars in 2011 than 2010.  This represents and increase of 31%. and not the 139% which is meaningless.

How do I get the 31% to display without typing 500 new formulas

Commented:
21Dewsbury,

The following code will convert the sub-totals formula in column F to the correct one...
``````Sub Fix_Subtotal()
Dim xLast_Row As Long
Dim xCell As Range

xLast_Row = ActiveSheet.Range("A1").SpecialCells(xlLastCell).Row

For Each xCell In Range("F2:F" & xLast_Row)
If Left(xCell.Formula, 13) = "=SUBTOTAL(9,F" Then xCell.Formula = "=E" & xCell.Row & "/C" & xCell.Row
Next

End Sub
``````
Regards,
Brian.

Commented:
21Dewsbury,

Obviously, the above is hard-coded for this particular layout. If you're interested, it could be made more generic by passing it particular columns and having it replace any sub-totals formula by the equivalent of the one found in the preceding non-sub-total cell (or, more simply, the second row).

Regards,
Brian.

Commented:
Thanks Brian, that will do nicely

Commented:
Thanks, 21Dewsbury!

Do more with