Results 1 to 1 of 1

Pivot Tables VBA

Threaded View

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

    Pivot Tables VBA

    Hi all,

    I m a newbie in using VBA and now I come across creating pivot table.

    Here is the code but it said there is runtime error 438:Object doesnt support this property or method.

    Sub PivotTable()
    Dim Pt As PivotTable
    Dim strField1, strField2  As String
    
        strField1 = Selection.Cells(1, 1).Text
        strField2 = Selection.Cells(1, 2).Text
        
        Worksheets("sheet1").Activate
    
    'Runtime error 438:Object doesnt support this property or method.   
        ActiveWorkbook.PivotCaches.create(SourceType:=xlDatabase, _
            SourceData:="=Sheet1!R1C1:R500C11").CreatePivotTable TableDestination:="", _
               TableName:="ItemList"
    
        'Set a Pivot Table variable to our new Pivot Table
        Set Pt = ActiveSheet.PivotTables("ItemList")
    
        'Place the Pivot Table to Start from A3 on the new sheet
        ActiveSheet.PivotTableWizard TableDestination:=Cells(1, 1)
    
        'Move the list heading to the Row Field
        'Pt.AddFields RowFields:=strField1, strField2
        'Pt.AddFields RowFields:
        'Move the list heading to the Data Field
        'Pt.PivotFields(strField).Orientation = xlDataField
        
        With Pt
            .SmallGrid = False
            .AddFields RowFields:=Array("customer_code", "liner_code"), ColumnFields:=Array("condition_code")
            .PivotFields("in_date").Orientation = xlDataField
            '.Format xlReport6
        End With
        
    End Sub
    Could anyone plot the error? Thanks a lot!!
    Last edited by Paul; 07-18-2011 at 11:35 PM. Reason: Added CODE tags for user. Please do so yourself in the future.

Thread Information

Users Browsing this Thread

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

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