I have this macro that creates a pivot table from a ranged data ("PvtData"). I keep getting run time error 1004 (Application defined or Object defined error) when the code is trying to add PivotFields.
Below is a portion of the code;
Workbooks(PivotFile).PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"PvtData", Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:="PvtResult", TableName:="PivotTable1", DefaultVersion _
:=xlPivotTableVersion14
'Work up to here
With ActiveSheet.PivotTables("PivotTable1").PivotFields("COB")
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Product")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Book")
.Orientation = xlRowField
.Position = 2
End With
I've tried recording the macro, which gives the same code line.
Changing the table destination to empty ("") does not help.