Results 1 to 3 of 3

Writing Code for creating pivot table

Threaded View

  1. #1
    Registered User
    Join Date
    07-18-2011
    Location
    Hong Kong
    MS-Off Ver
    Excel 2003, 2007, 2010
    Posts
    31

    Writing Code for creating pivot table

    Dear all,

    I wrote the code in creating pivot table for my source of data.
    However, when run the code, it prompts with the message. (I use Excel 2000)

    "Run-time error '438':
    Object doesnt support this property or method"

    Below please find the code also.

    ****************************
    Sub CreatePivotTable()
    
    Dim PTCache As PivotCache
    Dim PT As PivotTable
    
    Application.ScreenUpdating = False
    
    'Add a new sheet for the pivot table
    Worksheets.Add
    
    'Create the cache
    Set PTCache =
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase,
    SourceData:=Range("A1").CurrentRegion.Address)
    
    'Create the pivot table
    Set PT = ActiveSheet.PivotTables.Add(PivotCache:=PTCache,
    TableDestination:=Range("A3"))
    
    'Specify the fields
    With PT
    .PivotFields("street").Orientation = xlColumnField
    .PivotFields("condition_code").Orientation = xlColumnField
    .PivotFields("customer_code").Orientation = xlRowField
    .PivotFields("liner_code").Orientation = xlRowField
    .PivotFields("cont_type_code").Orientation = xlRowField
    .DisplayFieldCaptions = False
    End With
    
    Application.ScreenUpdating = True
    
    End Sub
    ****************************

    Thanks in advance!!

    Darwin Chan
    Attached Files Attached Files
    Last edited by pike; 10-26-2011 at 01:57 AM. Reason: add code tags for newbie PM rule

Thread Information

Users Browsing this Thread

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

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