Excel Sub-Totals : Getting the Percentages Calculating Correctly


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.

Patrick O'DeaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi, 21Dewsbury.

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

Gašper KamenšekExcel MVPCommented:

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.
Patrick O'DeaAuthor Commented:
Hi folks,
Thanks for your contributions.
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

Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.


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

End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

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).

Patrick O'DeaAuthor Commented:
Thanks Brian, that will do nicely
Thanks, 21Dewsbury!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.