Sub CreateSummaryReportUsingPivot()
' Create Pivot Table (PT) for a summary report
' Region in the rows in PT and products as columns in PT
Dim WSD As Worksheet
Dim PTCache As PivotCache
Dim PT As PivotTable
Dim PRange As Range
Set WSD = Worksheets("Data")
' Delete any prior Pivot Tables
For Each PT In WSD.PivotTables
PT.TableRange2.Clear
Next PT
' Define input area and set up a Pivot Cache
FinalRow = WSD.Cells(65536, 1).End(xlUp).Row
Set PRange = WSD.Cells(1, 1).Resize(FinalRow, 8)
Set PTCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=PRange.Address)
Set PT = PTCache.CreatePivotTable(TableDestination:=WSD.Range("J2"), TableName:="PivotTable1")
PT.ManualUpdate = True
' Set up row fields
PT.AddFields RowFields:="Region", ColumnFields:="Product"
' Set up data fields
With PT.PivotFields("Revenue")
.Orientation = xlDataField
.Function = xlSum
.Position = 1
End With
' Code does not display total row or column
With PT
.ColumnGrand = False
.RowGrand = False
.NullString = "0"
End With
' Calculate PT
PT.ManualUpdate = False
PT.ManualUpdate = True
' PT.TableRange2 contains the results. Move these to J10 (offset 2 col)
' as values, not a real PT.
PT.TableRange2.Offset(1, 0).Copy
WSD.Range("J10").PasteSpecial xlPasteValues
' Delete original PT & the Pivot Cache
PT.TableRange2.Clear
Set PTCache = Nothing
End Sub