Hi team,
I'm simply trying to create a pivot table in Sheet 2 from data in Sheet 1.
A run-time error (number 5) throws up when I'm stepping through the code and highlights the last portion of the code.
Any help would be greatly appreciated.
Thanks,
Brad.
I'm simply trying to create a pivot table in Sheet 2 from data in Sheet 1.
A run-time error (number 5) throws up when I'm stepping through the code and highlights the last portion of the code.
Any help would be greatly appreciated.
Thanks,
Brad.
VBA Code:
Sub CreatePivot()
Dim pc As PivotCache
Dim pt As PivotTable
Set pc = ThisWorkbook.PivotCaches.Create( _
SourceType:=xlDatabase, _
SourceData:=Worksheets("Sheet1").Range("A1").CurrentRegion.Address, _
Version:=xlPivotTableVersion15)
Worksheets("Sheet2").Select
Range("A1").Select
Set pt = pc.CreatePivotTable( _
TableDestination:=ActiveCell, _
TableName:="Month1Pivot")
End Sub