Pivot table grand total

Darren Smith

Well-known Member
Joined
Nov 23, 2020
Messages
631
Office Version
  1. 2019
Platform
  1. Windows
The pivot table puts its grand total below I need it above the table.
This is my code can see what is wrong with it.

VBA Code:
Sub Grand_Totals()

   Dim ws As Worksheet
   Dim lRow As Long
   Dim lCol As Long
   Dim rngA As Range
   Dim rngB As Range
   Dim rngC As Range
   Dim rngD As Range
   Dim rngE As Range
   Dim rngF As Range
   Dim rngG As Range
   Dim rngH As Range
   Dim rngI As Range
   Dim rngJ As Range
   Dim rngK As Range

   Set ws = ThisWorkbook.Worksheets("Pro Table")
   
   With ws
   
   lRow = Cells.Find(What:="*", _
                    After:=Range("A1"), _
                    LookAt:=xlPart, _
                    LookIn:=xlFormulas, _
                    SearchOrder:=xlByRows, _
                    SearchDirection:=xlPrevious, _
                    MatchCase:=False).Row

   Set rngA = .Range("C12" & lRow)
   Set rngB = .Range("D12" & lRow)
   Set rngC = .Range("E12" & lRow)
   Set rngD = .Range("F12" & lRow)
   Set rngE = .Range("G12" & lRow)
   Set rngF = .Range("H12" & lRow)
   Set rngG = .Range("I12" & lRow)
   Set rngH = .Range("J12" & lRow)
   Set rngI = .Range("K12" & lRow)
   Set rngJ = .Range("L12" & lRow)
   Set rngK = .Range("M12" & lRow)




.Range("C9") = WorksheetFunction.Sum(rngA)
.Range("D9") = WorksheetFunction.Sum(rngB)
.Range("E9") = WorksheetFunction.Sum(rngC)
.Range("F9") = WorksheetFunction.Sum(rngD)
.Range("G9") = WorksheetFunction.Sum(rngE)
.Range("H9") = WorksheetFunction.Sum(rngF)
.Range("I9") = WorksheetFunction.Sum(rngG)
.Range("J9") = WorksheetFunction.Sum(rngH)
.Range("K9") = WorksheetFunction.Sum(rngI)
.Range("L9") = WorksheetFunction.Sum(rngJ)
.Range("M9") = WorksheetFunction.Sum(rngK)

    
    End With
    
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,214,636
Messages
6,120,666
Members
448,977
Latest member
moonlight6

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