VBA How do I return the address of Grand Total in a Pivottable

Ziggy12

Active Member
Joined
Jun 26, 2002
Messages
365
I need to find the grand total label in a pivottable. The cell where the heading Grand Total is.
The Grand Total will move depending on data in labels in preceeding column headings.

cheers
ziggy
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
You can have a Grand Total cell for columns and for rows - this function will return whichever you specify (pass 1 for the second argument (or omit) for row totals, or 2 for column):
Code:
Function GetGrandTotalCell(pt As PivotTable, Optional RowOrCol As Integer = 1) As Range
    Dim rng As Range
    If RowOrCol = 1 Then
        Set rng = pt.RowRange
    ElseIf RowOrCol = 2 Then
        Set rng = pt.ColumnRange
    Else
        Exit Function
    End If
    With rng
        Set GetGrandTotalCell = .Cells(.Cells.Count)
    End With
End Function
 
Upvote 0
Have been giving this a go but what arguments are passed to the function and how.
The pivottable name is Pivottable 4 on sheet1, cell "B3"

cheers
ziggy
 
Upvote 0
You pass an actual pivot table object:
Code:
msgbox getgrandtotalcell(sheets("sheet1").pivottables("pivottable4"), 1)
for example
 
Upvote 0
Couldn't get it to work. Only returned GrandTotal not the address of the cell. Noticed that (.cells.count) had a value of 18 but that didn't seem to related to the pivot table.

Have selected a cell in the column feilds and incremented a long till it came to Grand Total and returned the active cell address.

ziggy
 
Upvote 0
It returns an actual range object, so if you added .address onto that code you would see the address.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,719
Members
452,939
Latest member
WCrawford

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