+ Reply to Thread
Results 1 to 3 of 3

PivotTable code

  1. #1
    Registered User
    Join Date
    03-22-2018
    Location
    Rotterdam, Netherlands
    MS-Off Ver
    2013
    Posts
    9

    PivotTable code

    I'm trying to create a pivot table with vba and I keep receiving error 438. The Tabledestioation doesn't capitalize in my code as if it wasn't recognized.

    This is the code I'm using

    Sub Pivottable()

    Dim Drange As Range

    Dim DSheet As Worksheet

    Dim PCache As PivotCache

    Dim Ptable As Pivottable


    LastRow = Worksheets("ex10").Cells(Rows.count, 1).End(xlUp).Row
    LastCol = Worksheets("ex10").Cells(1, Columns.count).End(xlToLeft).Column

    Set Drange = Worksheets("ex10").Cells(1, 1).Resize(LastRow, LastCol)

    Set DSheet = Worksheets("ex10")

    Set PCache = Worksheets("ex10").PivotCaches.Create(SourceType:=xlDatabase, SourceData:=Drange).CreatePivotTable(Tabledestination:=DSheet.Cells(9, 9), TableName:="Ptable")

    ' I also tried {.CreatePivotTable Tabledestination:=DSheet.Cells(9, 9), TableName:="Ptable" } in vain



    Set Ptable = PCache.CreatePivotTable(Tabledestination:=PSheet.Cells(1, 1), TableName:="PTable")


    End Sub

  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: PivotTable code

    Hi,

    Please use code tags when posting code.

    A Worksheet does not have a PivotCaches property, which is the cause of the error. You should be referring to the Workbook instead.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Registered User
    Join Date
    03-22-2018
    Location
    Rotterdam, Netherlands
    MS-Off Ver
    2013
    Posts
    9

    Re: PivotTable code

    Hello,

    I did that and now it gives me error 424, object required

+ 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. How to use pivottable report filter in code
    By j_Southern in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-06-2018, 01:27 PM
  2. [SOLVED] VBA code asistance with If Function to check PivotTable value
    By sintek in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-13-2016, 07:41 AM
  3. VB code to add outside border to Pivottable
    By mrazexcel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-22-2016, 09:49 PM
  4. PivotTable: change multi report filters code
    By saudi_red_neck in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-25-2014, 10:40 AM
  5. [SOLVED] Pivottable Field items code -problems
    By Rayo K in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-27-2006, 06:00 PM
  6. [SOLVED] Pivottable code problem
    By Rayo K in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-25-2006, 06:40 PM
  7. Replies: 0
    Last Post: 01-29-2006, 07:40 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