Creating Pivot Table with VBA
Posted by Skip Bisconer on December 04, 2000 8:50 PM
I have been trying to make this VBA code work for me to create a Pivot table. Can some one tell me why I error out and SET PT here is the code I'm tring to make work. The .PivotFields are all on one line, they just word wrap in this box.
Dim PTCache As PivotCache
Dim PT As PivotTable
Set PTCache = ActiveWorkbook.PivotCaches.Add _
(SourceType:=xlDatabase, _
SourceData:=Range("A1").CurrentRegion.Address)
****" This is the problem area"*****
Set PT = PTCache.CreatePivotTable _
(TableDestination:="", _
TableName:="PivotTable1")
With PT
.PivotFields("CallCode").Orientation = xlPageField
.PivotFields("GraphCode").Orientation = xlColumnField
.PivotFields("Date").Orientation = xlRowField
.PivotFields("GraphCode").Orientation = xlDataField
End With