I have written a macro to add a pivot chart in my Excel. I am getting an
Application-defined or object-defined error
in the following line. Can anybody help me with this?
Set DSheet = ActiveWorkbook.Worksheets("Sheet1")
Worksheets("Sheet1").Activate
LastRow = DSheet.Cells(DSheet.Rows.Count, 1).End(xlUp).Row
LastCol = DSheet.Cells(1, DSheet.Columns.Count).End(xlToLeft).Column
Set PRange = DSheet.Cells(1, 1).Resize(LastRow, LastCol)
Table1_Start_Line = 2
Table1_End_Line = Table1_Start_Line + LastRow
Column_Line = LastCol + 2
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=PRange, Version:=xlPivotTableVersion15).CreatePivotTable TableDestination:=DSheet.Cells(Table1_Start_Line, Column_Line), TableName:="PivotTable", DefaultVersion:=xlPivotTableVersion15