I am trying to create a pivot table, I would like the table on a diffrent tab then that of the data. Below is the code I am using, it is running all the way through not erroring out but my screen comes up as blank. Can some one tell me why my code is not pulling in the correct data or why the tab is blank?
HTML:
'Creating Pivot Table
Sub Create_Pivot_Table()
Sheets.Add After:=Sheets(Sheets.Count)
ActiveSheet.Name = "Pivot_Table"
Range("A1").Select
Dim WSD As Worksheet
Dim PL As Worksheet
Dim PTCache As PivotCache
Dim PT As PivotTable
Dim PRange As Range
Dim FinalRow As Long
Set WSD = Worksheets("Pivot_Table")
Set PL = Worksheets("AP_Parking_Lot")
'Delete any Prior Pivot Tables
For Each PT In WSD.PivotTables
PT.TableRange2.Clear
Next PT
'Define Input area and set up a Pivot Cache
Sheets("AP_Parking_Lot").Select
FinalRow = PL.Cells(Application.Rows.Count, 1).End(xlUp).Row
FinalCol = PL.Cells(1, Application.Columns.Count).End(xlToLeft).Column
Set PRange = PL.Cells(1, 1).Resize(FinalRow, FinalCol)
Set PTCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=PRange.Address)
'Create the Pivot Table from the Pivot Cache
Sheets("Pivot_Table").Select
Set PT = PTCache.CreatePivotTable(TableDestination:=WSD.Cells(2, FinalCol + 2), TableName:="PivotTable1")
'Turn off updating while building the table
PT.ManualUpdate = True
'set up the row & Column fields
PT.AddFields RowFields:=Array("Client", "Prof. Center", "Vendor", "PO Number", "Aging Days", "Document Date", "Posting Date", "Reference", "Text", "Document Number", "Invoice Number", "WBS", "GL ACCT")
'set up the data fields
With PT.PivotFields("Inv. Amount")
.NumberFormat = "_(* #,##0.00_);_(* (#,##0.00);_(* ""-""??_);_(@_)"
End With
'Calc the pivot Table
PT.ManualUpdate = False
PT.ManualUpdate = True
'Format Pivot Table
PT.ShowTableStyleRowStripes = True
With PT
.ColumnGrand = False
.RowGrand = False
.RepeatAllLabels xlRepeatLabels
End With
WSD.Activate
Range("A2").Select
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub