Hello,
I'm writing a little piece of code for something I'm doing at work and I'm having trouble with a persistent error.
I'm taking data from 5 sheets on a work book, combining it and then creating a pivot table. I have the first part, but the Pivot table is giving me some trouble. I don't know much about the pivottable object so I just used the "record macro" feature.
The second line of my recorded code is giving me an error. It says Object defined or application defined error. I have bypassed it using the on error handler but then it doesn't do any of the other actions besides create the initial pivot table template. Any help would be appreciated.
Range("B9").Select
'Error begins here
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= "Sheet1!R6C1:R14C14").CreatePivotTable TableDestination:="[Book1]Sheet2!R2C2", TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion10
'Error ends here
ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:=Array( _
"PCT Eng. Division", "Year", "PCT Lead")
ActiveSheet.PivotTables("PivotTable1").PivotFields("PCT Eng. Hours"). _
Orientation = xlDataField
With ActiveSheet.PivotTables("PivotTable1").PivotFields("PCT Eng. Division")
.PivotItems("BTS").Visible = False
End With
I'm writing a little piece of code for something I'm doing at work and I'm having trouble with a persistent error.
I'm taking data from 5 sheets on a work book, combining it and then creating a pivot table. I have the first part, but the Pivot table is giving me some trouble. I don't know much about the pivottable object so I just used the "record macro" feature.
The second line of my recorded code is giving me an error. It says Object defined or application defined error. I have bypassed it using the on error handler but then it doesn't do any of the other actions besides create the initial pivot table template. Any help would be appreciated.
Range("B9").Select
'Error begins here
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= "Sheet1!R6C1:R14C14").CreatePivotTable TableDestination:="[Book1]Sheet2!R2C2", TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion10
'Error ends here
ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:=Array( _
"PCT Eng. Division", "Year", "PCT Lead")
ActiveSheet.PivotTables("PivotTable1").PivotFields("PCT Eng. Hours"). _
Orientation = xlDataField
With ActiveSheet.PivotTables("PivotTable1").PivotFields("PCT Eng. Division")
.PivotItems("BTS").Visible = False
End With