I'm trying to create a pivot table with vba and I keep receiving error 438. The Tabledestioation doesn't capitalize in my code as if it wasn't recognized.
This is the code I'm using
Sub Pivottable()
Dim Drange As Range
Dim DSheet As Worksheet
Dim PCache As PivotCache
Dim Ptable As Pivottable
LastRow = Worksheets("ex10").Cells(Rows.count, 1).End(xlUp).Row
LastCol = Worksheets("ex10").Cells(1, Columns.count).End(xlToLeft).Column
Set Drange = Worksheets("ex10").Cells(1, 1).Resize(LastRow, LastCol)
Set DSheet = Worksheets("ex10")
Set PCache = Worksheets("ex10").PivotCaches.Create(SourceType:=xlDatabase, SourceData:=Drange).CreatePivotTable(Tabledestination:=DSheet.Cells(9, 9), TableName:="Ptable")
' I also tried {.CreatePivotTable Tabledestination:=DSheet.Cells(9, 9), TableName:="Ptable" } in vain
Set Ptable = PCache.CreatePivotTable(Tabledestination:=PSheet.Cells(1, 1), TableName:="PTable")
End Sub
Bookmarks