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

Jerry Sullivan

MrExcel MVP
Joined
Mar 18, 2010
Messages
8,787
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.)
 

Forum statistics

Threads
1,081,543
Messages
5,359,431
Members
400,526
Latest member
Brook1083

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top