Adding pivot tables into a macro?

klo138

New Member
Joined
Sep 30, 2010
Messages
5
Hello-
So I am trying to add a pivot table into a macro to sort my data. I just recorded the macro while setting up the pivot table I needed but now it has an error almost immediately. I changed a few things around hoping that would do it but nope. The red text is where the error is right now.
HELP!!!! please

Sub OperatorPivot()
'
' OperatorPivot Macro
'
'
Sheets("Map Data").Select
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _"Map Data!R1C1:R644C17", Version:=xlPivotTableVersion10).CreatePivotTable _
TableDestination:="Operator Data!R1C1", TableName:="PivotTable5", _
DefaultVersion:=xlPivotTableVersion10
Sheets("Operator Data").Select
Cells(1, 1).Select
With ActiveSheet.PivotTables("PivotTable5").PivotFields("OPERATOR")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable5").PivotFields("Bits to KOP")
.Orientation = xlRowField
.Position = 2
End With
ActiveSheet.PivotTables("PivotTable5").AddDataField ActiveSheet.PivotTables( _
"PivotTable5").PivotFields("# Count Operator"), "Sum of # Count Operator", _
xlSum
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
You can correct one error by removing the underscore in the SourceData parameter:

ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase,
SourceData:= _"Map Data!R1C1:R644C17", Version:=xlPivotTableVersion10).CreatePivotTable _
TableDestination:="Operator Data!R1C1", TableName:="PivotTable5", _
DefaultVersion:=xlPivotTableVersion10

Pivot Table is overkill if all you want to do is sort your data.
 
Upvote 0

Forum statistics

Threads
1,215,766
Messages
6,126,758
Members
449,336
Latest member
p17tootie

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top