Creating a Pivot table Cache

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")
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
When that error occurs, which line of code is highlighted in the VB Editor?

Try running the code, then when it pauses at the error, paste this code into the Immediate Window of the VB Editor:
?PivotRange.Address(1,1,xlA1,1)

Post the reply that comes back when you hit enter.

(If the Immediate Window isn't visible in the VB Editor, hit Ctrl+G to display it.)
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top