Hey guys, I'm new to the forum but over the past week found a lot of useful data that has lead me to my first problem I am unable to resolve using other's posts.
I've created a pivot table that is placed on an existing worksheet using a dynamic named table for the range. I've been able to create a macro that works fine when the table is placed in a new worksheet by emptying the table destination and removing a few lines, but not so much when I try and place the table in an existing worksheet. This leads me to believe my issue lies somewhere in the table destination area. Below I've copied and pasted the script with the bold area in question. I've also pasted below that what I've tried to do to "fix" it.
Sub PT_Field_Summary()
'
' PT_Field_Summary Macro
'
'
ActiveWorkbook.PivotCaches.<wbr>Create(SourceType:=xlDatabase, SourceData:= _
"Dynamic_Field_Summary", Version:=<wbr>xlPivotTableVersion10).<wbr>CreatePivotTable _
TableDestination:="Field Summary!R1C16", TableName:="PivotTable7", _
DefaultVersion:=<wbr>xlPivotTableVersion10
Sheets("Field Summary").Select
Cells(1, 16).Select
ActiveWorkbook.<wbr>ShowPivotTableFieldList = True
With ActiveSheet.PivotTables("<wbr>PivotTable7").PivotFields("<wbr>Enterprise")
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("<wbr>PivotTable7").PivotFields("<wbr>Field ")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("<wbr>PivotTable7").AddDataField ActiveSheet.PivotTables( _
"PivotTable7").PivotFields("<wbr>Planted Acres"), "Sum of Planted Acres", xlSum
ActiveSheet.PivotTables("<wbr>PivotTable7").AddDataField ActiveSheet.PivotTables( _
"PivotTable7").PivotFields("<wbr>Harvested Acres"), "Sum of Harvested Acres", xlSum
With ActiveSheet.PivotTables("<wbr>PivotTable7").DataPivotField
.Orientation = xlColumnField
.Position = 2
End With
ActiveSheet.PivotTables("<wbr>PivotTable7").AddDataField ActiveSheet.PivotTables( _
"PivotTable7").PivotFields("<wbr>lbs "), "Sum of lbs ", xlSum
ActiveWorkbook.<wbr>ShowPivotTableFieldList = False
ActiveWindow.SmallScroll Down:=-3
End Sub
Using some google searches I was able to begin a "fix" listed below. I swore I had it working at the office earlier, but no avail now. I've changed the font on the area I played with.
ActiveWorkbook.PivotCaches.<wbr>Create(SourceType:=xlDatabase, SourceData:= _
"Dynamic_Field_Summary", Version:=<wbr>xlPivotTableVersion10).<wbr>CreatePivotTable _
TableDestination:=Worksheets("<wbr>Field Summary!").Range("P1"), TableName:="PivotTable7", _
DefaultVersion:=<wbr>xlPivotTableVersion10
When I save and attempt the macro from here I get a Run Time Error 9, subscript out of range.
I learned what an excel macro and pivot table was on Monday, making a lot of headway thanks to your community!
I've created a pivot table that is placed on an existing worksheet using a dynamic named table for the range. I've been able to create a macro that works fine when the table is placed in a new worksheet by emptying the table destination and removing a few lines, but not so much when I try and place the table in an existing worksheet. This leads me to believe my issue lies somewhere in the table destination area. Below I've copied and pasted the script with the bold area in question. I've also pasted below that what I've tried to do to "fix" it.
Sub PT_Field_Summary()
'
' PT_Field_Summary Macro
'
'
ActiveWorkbook.PivotCaches.<wbr>Create(SourceType:=xlDatabase, SourceData:= _
"Dynamic_Field_Summary", Version:=<wbr>xlPivotTableVersion10).<wbr>CreatePivotTable _
TableDestination:="Field Summary!R1C16", TableName:="PivotTable7", _
DefaultVersion:=<wbr>xlPivotTableVersion10
Sheets("Field Summary").Select
Cells(1, 16).Select
ActiveWorkbook.<wbr>ShowPivotTableFieldList = True
With ActiveSheet.PivotTables("<wbr>PivotTable7").PivotFields("<wbr>Enterprise")
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("<wbr>PivotTable7").PivotFields("<wbr>Field ")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("<wbr>PivotTable7").AddDataField ActiveSheet.PivotTables( _
"PivotTable7").PivotFields("<wbr>Planted Acres"), "Sum of Planted Acres", xlSum
ActiveSheet.PivotTables("<wbr>PivotTable7").AddDataField ActiveSheet.PivotTables( _
"PivotTable7").PivotFields("<wbr>Harvested Acres"), "Sum of Harvested Acres", xlSum
With ActiveSheet.PivotTables("<wbr>PivotTable7").DataPivotField
.Orientation = xlColumnField
.Position = 2
End With
ActiveSheet.PivotTables("<wbr>PivotTable7").AddDataField ActiveSheet.PivotTables( _
"PivotTable7").PivotFields("<wbr>lbs "), "Sum of lbs ", xlSum
ActiveWorkbook.<wbr>ShowPivotTableFieldList = False
ActiveWindow.SmallScroll Down:=-3
End Sub
Using some google searches I was able to begin a "fix" listed below. I swore I had it working at the office earlier, but no avail now. I've changed the font on the area I played with.
ActiveWorkbook.PivotCaches.<wbr>Create(SourceType:=xlDatabase, SourceData:= _
"Dynamic_Field_Summary", Version:=<wbr>xlPivotTableVersion10).<wbr>CreatePivotTable _
TableDestination:=Worksheets("<wbr>Field Summary!").Range("P1"), TableName:="PivotTable7", _
DefaultVersion:=<wbr>xlPivotTableVersion10
When I save and attempt the macro from here I get a Run Time Error 9, subscript out of range.
I learned what an excel macro and pivot table was on Monday, making a lot of headway thanks to your community!