Hi All,
I have run into an error in creating a pivot table. The error says object required, but I believe that I already have an object there. I'm sure this will be easy for the wiz' out there! The error occurs after the pivot table is created and where I start the "with PT." Thanks!
samplewb.xlsm
Sub Pivot()
Dim PTCache As PivotCache
Dim PT As PivotTable
'Create Cache
Set PTCache = ActiveWorkbook.PivotCaches.Create( _
SourceType:=xlDatabase, _
SourceData:=Sheets("Breakdown").Range("a1").CurrentRegion)
'Add a New WS to the WB
Worksheets.Add.Name = "Pivot"
'Create Pivot Table
Set PT = ActiveSheet.PivotTables.Add( _
PivotCache:=PTCache, _
tabledestination:=Range("a1"))
'Specify the fields
With PT
.PivotFields("Notification Reference Date").Orientation.xlColumnField
.PivotFields("Equipment Name").Orientation.xlRowField
.PivotFields("District Text").Orientation.xlRowField
.PivotFields("Equipment Name").Orientation.xlDataField
'no field captions
.DisplayFieldCaptions = False
End With
Range("B2").Select
Selection.Group Start:=True, End:=True, Periods:=Array(False, False, False, _
False, True, False, False)
End Sub
Bookmarks