I'm trying to record a macro that will create a pivot table. I want the pivot table to display the "division" field name in both the row and values section of the pivot table so that it outputs the number of teams in each division.
For example:
Advanced: 15
Intermediate: 20
Beginner: 5
After I record the macro and try to run it I get the error message -
Run-time error '1004': Method 'CreatePivotTable' of object 'PivotCache' failed
This is what the VBA looks like:
Sub Macro1()
'
' Macro1 Macro
'
'
Sheets.Add
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"2017-USA-Spikeball-East-Tour--P!R1C1:R51C40", Version:=xlPivotTableVersion14 _
).CreatePivotTable TableDestination:="Sheet1!R3C1", TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion14
Sheets("Sheet1").Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields("division")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("division"), "Count of division", xlCount
End Sub
Solved by V. A. in 22 mins