Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default VB Reference to Grand Total row in Pivot Table

How can I refer to the Grand Total row of a Pivot Table in VBA? For example,
if I wanted a sub to change the row height of the Grand Total row. (Using a
named range doesn't work because the range moves when the table is
refreshed). Thanks


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default VB Reference to Grand Total row in Pivot Table

use GetPivotData()

from Help:

Example
In this example, Microsoft Excel returns the quantity of chairs in the
warehouse to the user. This example assumes a PivotTable report exists on the
active worksheet. Also, this example assumes that, in the report, the title
of the data field is "Quantity", a field titled "Warehouse" exists, and a
data item titled "Chairs" exists in the Warehouse field.

Sub UseGetPivotData()

Dim rngTableItem As Range

' Get PivotData for the quantity of chairs in the warehouse.
Set rngTableItem = ActiveCell. _
PivotTable.GetPivotData("Quantity", "Warehouse", "Chairs")

MsgBox "The quantity of chairs in the warehouse is: " & rngTableItem.Value

End Sub


"John" wrote:

How can I refer to the Grand Total row of a Pivot Table in VBA? For example,
if I wanted a sub to change the row height of the Grand Total row. (Using a
named range doesn't work because the range moves when the table is
refreshed). Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default VB Reference to Grand Total row in Pivot Table

Not sure whether you want a reference to the row or just to the grand
totals. Here is some sample code for selecting the grand totals in two
different but similar ways.


Sub selectRowGrandTotals(Optional pt As PivotTable)
If pt Is Nothing Then Set pt = getPivotTable
If Not pt Is Nothing Then
Sheets(pt.Parent.Name).Select
RowGrandTotalsRange(pt).Select
Else
MsgBox "No pivot tables on the active sheet."
End If
End Sub

Sub selectColumnGrandTotals(Optional pt As PivotTable)
Dim X As Range
If pt Is Nothing Then Set pt = getPivotTable
If Not pt Is Nothing Then
Set X = pt.DataBodyRange
With pt
.ColumnGrand = True
End With
Sheets(pt.Parent.Name).Select
X.Range(Cells(X.Rows.Count, 1), Cells(X.Rows.Count,
X.Columns.Count)).Select
Else
MsgBox "No pivot tables on the active sheet."
End If
End Sub

Function RowGrandTotalsRange(Ptable As PivotTable) As Range
With Ptable
.RowGrand = True
End With
Set RowGrandTotalsRange = Ptable.DataBodyRange.Range( _
Sheets(Ptable.Parent.Name).Cells(1, _
Ptable.DataBodyRange.Columns.Count), _
Sheets(Ptable.Parent.Name).Cells
(Ptable.DataBodyRange.Rows.Count, _
Ptable.DataBodyRange.Columns.Count))
End Function
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Duplicate Running Total Grand Total In Pivot Table Mathew P Bennett[_2_] Excel Discussion (Misc queries) 1 August 17th 08 03:13 AM
Pivot Table (Grand Total) IF Statement[_2_] Excel Discussion (Misc queries) 1 November 19th 07 07:07 PM
Pivot Table Grand Total Stonewall Excel Discussion (Misc queries) 3 June 12th 07 12:25 AM
Get grand total from pivot table karimhemani Excel Programming 2 March 23rd 07 03:58 PM
% of Running Total to Grand Total in Pivot Table David Excel Programming 0 August 17th 05 08:24 PM


All times are GMT +1. The time now is 12:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"