I'm having difficulty with the last line of code which is producing an error 1004 - application defined or object defined error.
Please could someone take a look and offer advice?
Sub CreatePT()
Dim wsCOMB As Worksheet
Dim wsPT As Worksheet
Dim PTCache As PivotCache
Dim PT As PivotTable
Dim PRange As Range
Dim FinalRow As Long
Set wsCOMB = Worksheets("COMBINED")
Set wsPT = Worksheets("Pivot Table")
' Delete any prior pivot tables
For Each PT In wsPT.PivotTables
PT.TableRange2.Clear
Next PT
' Define input area and set up a pivot cache
FinalRow = wsCOMB.Cells(5000, 1).End(xlUp).Row
Set PRange = wsCOMB.Cells(1, 1).Resize(FinalRow, 8)
Set PTCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=PRange.Address)
Set PT = PTCache.CreatePivotTable(TableDestination:=wsPT.Range("B4"), TableName:="PivotTable1")
End Sub
Thanks,
Louise
Bookmarks