+ Reply to Thread
Results 1 to 2 of 2

Run-time error 440: Method create of object 'PivotCaches' failed

  1. #1
    Registered User
    Join Date
    05-18-2017
    Location
    Cape Town
    MS-Off Ver
    2013
    Posts
    2

    Run-time error 440: Method create of object 'PivotCaches' failed

    Hi Everyone

    I need assistance with the following code. I have exactly the same code for 2 other worksheets and it runs perfectly. But with this one i get the above mentioned error in the line highlighted in bold. My source data is essentially 29 columns with headings starting from row 3. As you can see the for each spreadsheet I find the last row which is used to define a range for the pivot table.

    I am not actually experienced with creating pivot tables via vba. Is there something I am missing that causes the pivotcache method to fail? Your help would be much appreciated.

    Sub CreatePivottable3()
    Dim wsData1 As Worksheet
    Dim wsPT1 As Worksheet
    Dim PT_cache1 As PivotCaches
    Dim PT1, PT2, PT3, PT4 As PivotTable
    Dim Lastrow1 As Long
    Dim Prange1 As Range
    Dim objfield1, objfield2, objfield3, objfield4 As PivotField

    With ThisWorkbook
    Set wsData1 = .Worksheets("JointLifeTLA")
    Set wsPT1 = .Worksheets("PivotTableJointLifeTLA")
    End With

    'determines last row number based on column A
    Lastrow1 = wsData1.Cells(Rows.Count, 1).End(xlUp).Row
    Set Prange1 = wsData1.Range(wsData1.Cells(3, 1), wsData1.Cells(Lastrow1, 29))
    'Creating pivot table cache
    Set PT_cache1 = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=Prange1, Version:=xlPivotTableVersion15)
    'create pivot table
    Set PT1 = PT_cache1.CreatePivotTable(TableDestination:=wsPT.Cells(1, 1), TableName:="Pivot table sum of single premium")
    Set PT2 = PT_cache1.CreatePivotTable(TableDestination:=wsPT.Cells(40, 1), TableName:="Pivot table average single premium")
    Set PT3 = PT_cache1.CreatePivotTable(TableDestination:=wsPT.Cells(80, 1), TableName:="Pivot table Avearage Income")

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Run-time error 440: Method create of object 'PivotCaches' failed

    Hi,

    Perhaps this
    Please Login or Register  to view this content.
    Also, you really need to use code tags when posting code per the forum rules.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Run-time error 1004 Method Open of object Workbooks Failed
    By Rikimaru82 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-29-2016, 04:32 AM
  2. [SOLVED] run time error method value of object range failed
    By gloger in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-27-2015, 04:56 AM
  3. Addon error : Run-time error '1004': Method 'MacroOptions' of object '_Application' failed
    By jtcoleman in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 3
    Last Post: 02-05-2014, 12:23 PM
  4. Run-time-error 1004 -- Method 'Range' of object '_Global' failed
    By tilleyd in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-04-2012, 10:55 PM
  5. Run-time error '1004': Method 'Range' of object '_ Global' failed
    By mdvc in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-20-2011, 11:48 AM
  6. Run-time error '1004': Method 'Range' of object '_Global' failed
    By claremount in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 03-26-2010, 08:01 AM
  7. [SOLVED] run-time error, method 'paste' of object - worksheet failed.
    By Carl in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-29-2006, 12:15 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1