Help with Macro to create pivot table

ajc623

Board Regular
Joined
Nov 8, 2013
Messages
58
I am trying to have a macro that will create a pivot table on a sheet using the data from column C and D. I would like for this work on any sheet in the workbook and to run on the active sheet when the macro is run. When I make the pivot table I have no problem and it looks just like I want but when I run the macro it immediately has an error. Any help would be great.




Sub DailyTotals()
'
' DailyTotals Macro
'
' Keyboard Shortcut: Ctrl+Shift+T
'
Columns("C:D").Select
Range("D1").Activate
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"11-21!R1C3:R1048576C4", Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:="11-21!R3C11", TableName:="PivotTable5", DefaultVersion _
:=xlPivotTableVersion14
Sheets("11-21").Select
Cells(3, 11).Select
With ActiveSheet.PivotTables("PivotTable5").PivotFields("ITEM")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable5").AddDataField ActiveSheet.PivotTables( _
"PivotTable5").PivotFields("#"), "Count of #", xlCount
Range("L3").Select
With ActiveSheet.PivotTables("PivotTable5").PivotFields("Count of #")
.Caption = "Sum of #"
.Function = xlSum
End With
Range("K3").Select
With ActiveSheet.PivotTables("PivotTable5").PivotFields("ITEM")
.PivotItems("TIME").Visible = False
.PivotItems("UPS").Visible = False
.PivotItems("(blank)").Visible = False
End With
Range("K3").Select
ActiveSheet.PivotTables("PivotTable5").PivotFields("ITEM").AutoSort xlAscending _
, "ITEM"
ActiveWorkbook.ShowPivotTableFieldList = False
End Sub
 

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