Nested Subtotal adding two Grand Totals

ExcelNoob222

Board Regular
Joined
Jun 17, 2020
Messages
77
Office Version
  1. 365
Platform
  1. Windows
Hi,

When I do this manually using the subtotal menu under data I get only one grand total. However when I use the below VBA it adds two grand totals:

VBA Code:
Selection.Subtotal GroupBy:=3, Function:=xlSum, TotalList:=Array(8, 11), _
        Replace:=False, PageBreaks:=False, SummaryBelowData:=True
    Selection.Subtotal GroupBy:=5, Function:=xlSum, TotalList:=Array(8, 11), _
        Replace:=False, PageBreaks:=False, SummaryBelowData:=True
    Range("A1").Select

Any suggestions? Thanks.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
In case anyone else runs into this issue in the future, I was able to figure out this work around:

VBA Code:
On Error Resume Next
   Cells(Columns(5).Find(What:="*Grand Total*", LookIn:=xlValues).Row, 1).EntireRow.Delete
 
Upvote 0
Solution
It looks as though the user found a work around, but I also wanted to share what worked for me in not creating the second Grand Total to begin with. Like the original example, I ran two subtotal routines one after another and came up with two Grand Totals, but when I reset the range used for the second subtotal routine to cover the entire expanded range after the first subtotal routine, the second Grand Total doesn't get created.

VBA Code:
Set rngTargetScope = Range("ExecSumStart").CurrentRegion
rngTargetScope.Subtotal GroupBy:=intPresLoc, Function:=xlSum, TotalList:=Array(intHomesLoc, intNTVLoc, intFTVLoc, _
intFPVLoc, intPrcLoc, intELPLoc, intBaseLoc, intOptsLoc, intExcDLoc, intOOMDLoc, intOMDLoc, intLOTLoc, _
intVARLoc, intFIXLoc, intTDirLoc, intOSVLoc), Replace:=True, PageBreaks:=False, _
SummaryBelowData:=True
Set rngTargetScope = Range("ExecSumStart").CurrentRegion
rngTargetScope.Subtotal GroupBy:=intRgnLoc, Function:=xlSum, TotalList:=Array(intHomesLoc, intNTVLoc, intFTVLoc, _
intFPVLoc, intPrcLoc, intELPLoc, intBaseLoc, intOptsLoc, intExcDLoc, intOOMDLoc, intOMDLoc, intLOTLoc, _
intVARLoc, intFIXLoc, intTDirLoc, intOSVLoc), Replace:=False, PageBreaks:=False, _
SummaryBelowData:=True
 
Upvote 0

Forum statistics

Threads
1,226,110
Messages
6,188,988
Members
453,519
Latest member
pat3pet

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top