riemerco
08-30-2017, 09:32 AM
I need help rewriting VBA code for a pivot table.
I create the same pivot table dozens of times per month. My workbook always starts off with pre-existing "Detail" and "Summary" tabs. I then create a pivot table from all of the data on the "Detail" tab and use it to create a pivot table on the "Summary" tab. I need help standardizing the below VBA code so that it will work on any workbook I have open which already has a "Detail" tab and a "Summary" tab.
Sub Create_Pivot_Table()
'
' Create_Pivot_Table Macro
' Creates standard pivot table.
'
'
Cells.Select
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Detail!R1C1:R1048576C39", Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:="Summary!R1:R1048576", TableName:="PivotTable1", _
DefaultVersion:=xlPivotTableVersion14
Sheets("Summary").Select
Cells(1, 1).Select
End Sub
I create the same pivot table dozens of times per month. My workbook always starts off with pre-existing "Detail" and "Summary" tabs. I then create a pivot table from all of the data on the "Detail" tab and use it to create a pivot table on the "Summary" tab. I need help standardizing the below VBA code so that it will work on any workbook I have open which already has a "Detail" tab and a "Summary" tab.
Sub Create_Pivot_Table()
'
' Create_Pivot_Table Macro
' Creates standard pivot table.
'
'
Cells.Select
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Detail!R1C1:R1048576C39", Version:=xlPivotTableVersion14).CreatePivotTable _
TableDestination:="Summary!R1:R1048576", TableName:="PivotTable1", _
DefaultVersion:=xlPivotTableVersion14
Sheets("Summary").Select
Cells(1, 1).Select
End Sub