Code Chaser
New Member
- Joined
- Nov 23, 2016
- Messages
- 8
I am trying to create a basic Pivot Table. I have looked up how to do so on the internet, however, I seem to be running into an error when creating the pivot table Cache.
The error I receive is Run-time error '440 Method 'Create' of object 'PivotCaches' failed
My code is below. I am new to this site, if I can give you some sort of credit for answering let me know how and I'd be glad to give you the max. Thanks.
'Setting up Pivot tables for Memo Items sheet
ActiveWorkbook.Sheets("Details").Select
Range("a1").Select
'Pivot Table Variables
Dim Pivot_by_account_and_memo_col As Worksheet
Dim PCache As PivotCache
Dim ReconPivot As PivotTable
Dim PivotRange As Range
Dim DetailsRowCount As Long
Dim DetailsColCount As Long
Dim Details As Worksheet
'Create new sheet for PivotTable
On Error Resume Next
'Application.DisplayAlerts = False ''Dont think I need this line
Worksheets("PivotTable").Delete
On Error GoTo 0
Sheets("Details").Select
Sheets.Add Before:=ActiveSheet
ActiveSheet.Name = "Pivot by account and memo col"
Set Pivot_by_account_and_memo_col = Worksheets("Pivot by account and memo col")
Set Details = Worksheets("Details")
'Create Named Range for PivotTable range
Sheets("Details").Select
Range("A1").CurrentRegion.Select
Set PivotRange = Selection.CurrentRegion
'Creat Pivot Cache (Pivot Cache creates a replica of the data that you selected as the pivot table range)
Set PCache = ActiveWorkbook.PivotCaches.Create _
(SourceType:=xlDatabase, SourceData:=PivotRange)
'Create a blank PivotTable that uses the data in the cache that you just created
Set PTable = PCache.CreatePivotTable _
(TableDestination:=Pivot_by_account_and_memo_col.Cells(1, 1), TableName:="Recon Pivot")
The error I receive is Run-time error '440 Method 'Create' of object 'PivotCaches' failed
My code is below. I am new to this site, if I can give you some sort of credit for answering let me know how and I'd be glad to give you the max. Thanks.
'Setting up Pivot tables for Memo Items sheet
ActiveWorkbook.Sheets("Details").Select
Range("a1").Select
'Pivot Table Variables
Dim Pivot_by_account_and_memo_col As Worksheet
Dim PCache As PivotCache
Dim ReconPivot As PivotTable
Dim PivotRange As Range
Dim DetailsRowCount As Long
Dim DetailsColCount As Long
Dim Details As Worksheet
'Create new sheet for PivotTable
On Error Resume Next
'Application.DisplayAlerts = False ''Dont think I need this line
Worksheets("PivotTable").Delete
On Error GoTo 0
Sheets("Details").Select
Sheets.Add Before:=ActiveSheet
ActiveSheet.Name = "Pivot by account and memo col"
Set Pivot_by_account_and_memo_col = Worksheets("Pivot by account and memo col")
Set Details = Worksheets("Details")
'Create Named Range for PivotTable range
Sheets("Details").Select
Range("A1").CurrentRegion.Select
Set PivotRange = Selection.CurrentRegion
'Creat Pivot Cache (Pivot Cache creates a replica of the data that you selected as the pivot table range)
Set PCache = ActiveWorkbook.PivotCaches.Create _
(SourceType:=xlDatabase, SourceData:=PivotRange)
'Create a blank PivotTable that uses the data in the cache that you just created
Set PTable = PCache.CreatePivotTable _
(TableDestination:=Pivot_by_account_and_memo_col.Cells(1, 1), TableName:="Recon Pivot")