Thanks Greg!
I ended up rebuilding the code with some google research and was able to get it to work. The code is below. I appreciate your help.
Sub InsertPivotTable71500()
'Declare Variables
Dim PSheet As Worksheet
Dim DSheet As Worksheet
Dim PCache As PivotCache
Dim PTable As PivotTable
Dim PRange As Range
Dim LastRow8 As Long
Dim LastCol As Long
'Insert a New Blank Worksheet
On Error Resume Next
Application.DisplayAlerts = False
Worksheets("71500").Delete
Sheets.Add Before:=ActiveSheet
ActiveSheet.Name = "71500"
Application.DisplayAlerts = True
Set PSheet = Worksheets("71500")
Set DSheet = Worksheets("71500 Original")
'Define Data Range
LastRow8 = DSheet.Cells(Rows.Count, 1).End(xlUp).Row
LastCol = DSheet.Cells(1, Columns.Count).End(xlToLeft).Column
'Set PRange = DSheet.Cells(1, 1).Resize(LastRow, LastCol)
Set PRange = DSheet.Range("A4:U" & LastRow8)
'Define Pivot Cache
Set PCache = ActiveWorkbook.PivotCaches.Create _
(SourceType:=xlDatabase, SourceData:=PRange). _
CreatePivotTable(TableDestination:=PSheet.Cells(1, 1), _
TableName:="71500PivotTable")
'Insert Blank Pivot Table
Set PTable = PCache.CreatePivotTable _
(TableDestination:=PSheet.Cells(1, 1), TableName:="71500PivotTable")
'Insert Row Fields
With ActiveSheet.PivotTables("71500PivotTable").PivotFields("GL String")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("71500PivotTable").AddDataField ActiveSheet.PivotTables( _
"71500PivotTable").PivotFields("Debit"), "Sum of Debit", xlSum
ActiveSheet.PivotTables("71500PivotTable").AddDataField ActiveSheet.PivotTables( _
"71500PivotTable").PivotFields("Credit"), "Sum of Credit", xlSum
'Insert Column Fields
With ActiveSheet.PivotTables("71500PivotTable").PivotFields("Company CO")
.Orientation = xlColumnField
.Position = 2
End With
'Insert Column Fields
With ActiveSheet.PivotTables("71500PivotTable").PivotFields("Cost Center")
.Orientation = xlColumnField
.Position = 3
End With
'Insert Column Fields
With ActiveSheet.PivotTables("71500PivotTable").PivotFields("Region")
.Orientation = xlColumnField
.Position = 4
End With
End Sub
Bookmarks