I am trying to create a macro for a pivot table i am creating, but it gives me an error message whenver i try to run the macro. This is my code:
Sheets.Add
ActiveWorkbook.Worksheets("Summary").PivotTables("PivotTable3").PivotCache. _
CreatePivotTable TableDestination:="Sheet4!R3C1", TableName:="PivotTable3" _
, DefaultVersion:=xlPivotTableVersion12
Sheets("Sheet4").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable3").PivotFields( _
"Cost_Center_(Division)")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable3").PivotFields("Department")
.Orientation = xlColumnField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
"PivotTable3").PivotFields("Employee_Number"), "Count of Employee_Number", _
xlCount
End Sub
Sheets.Add
ActiveWorkbook.Worksheets("Summary").PivotTables("PivotTable3").PivotCache. _
CreatePivotTable TableDestination:="Sheet4!R3C1", TableName:="PivotTable3" _
, DefaultVersion:=xlPivotTableVersion12
Sheets("Sheet4").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable3").PivotFields( _
"Cost_Center_(Division)")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable3").PivotFields("Department")
.Orientation = xlColumnField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
"PivotTable3").PivotFields("Employee_Number"), "Count of Employee_Number", _
xlCount
End Sub