+ Reply to Thread
Results 1 to 6 of 6

Can't resolve PivotTable Property error.

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-13-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    378

    Question Can't resolve PivotTable Property error.

    I am trying to use the following code...

    Sub CreatePivotTable()
    
        Dim WSD As Worksheet
        Dim PTCache As PivotCache
        Dim PVT As PivotTable
        Dim PRange As Range
        Dim FinalRow As Long
        Dim FinalCol As Long
        Dim PVTRows As Long
        Dim PVTCols As Long
        Dim NewRow As Long
        Dim WS As Worksheet
        
        
    
        Application.ScreenUpdating = False
        Set WSD = Worksheets("StratixTimeReport")
        Set WS = Worksheets("Report Summary")
        For Each PVT In WSD.PivotTables
            PVT.TableRange2.Clear
        Next PVT
            FinalRow = WSD.Cells(Application.Rows.Count, 1).End(xlUp).Row
            FinalCol = WSD.Cells(1, Application.Columns.Count).End(xlToLeft).Column
            Set PRange = WSD.Cells(1, 1).Resize(FinalRow, FinalCol)
            Set PTCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=PRange.Address)
            Set PVT = PTCache.CreatePivotTable(TableDestination:=WS.Cells(1, 1), TableName:="PivotTable1")
            
            With PVT.PivotFields("Tech")
                .Orientation = xlRowField
                .Position = 1
            End With
            With PVT.PivotFields("Product")
                .Orientation = xlRowField
                .Position = 2
            End With
            
        ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
            "PivotTable1").PivotFields("Total Batch Items"), "Sum of Total Batch Items", _
            xlSum
        ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
            "PivotTable1").PivotFields("Elapsed Time"), "Sum of Elapsed Time", xlSum
        ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
            "PivotTable1").PivotFields("Expected Time"), "Sum of Expected Time", xlSum
        ActiveSheet.PivotTables("PivotTable1").CalculatedFields.Add _
            "Rate of Productivity", "='Expected Time' /'Elapsed Time'", True
        ActiveSheet.PivotTables("PivotTable1").PivotFields("Rate of Productivity"). _
            Orientation = xlDataField
    
        With ActiveSheet.PivotTables("PivotTable1").DataPivotField
            .Orientation = xlColumnField
            .Position = 1
        End With
        With ActiveSheet.PivotTables("PivotTable1").PivotFields( _
            "Sum of Rate of Productivity")
            .NumberFormat = "0.00%"
        End With
        With ActiveSheet.PivotTables("PivotTable1").PivotFields( _
            "Sum of Elapsed Time")
            .NumberFormat = "0.00"
        End With
            With PVT
                .ManualUpdate = True
                .ShowTableStyleColumnStripes = True
                .ShowTableStyleRowStripes = True
                .TableStyle2 = "PivotStyleMedium6"
                .ColumnGrand = False
                .RowGrand = True
                .RowAxisLayout xlCompactRow
                .ManualUpdate = False
                
            End With
    
        ActiveSheet.PivotTables("PivotTable1").DataPivotField.PivotItems( _
            "Sum of Rate of Productivity").Caption = "Rate of Productivity"
        ActiveSheet.PivotTables("PivotTable1").DataPivotField.PivotItems( _
            "Sum of Expected Time").Caption = "Total Expected Time"
        ActiveSheet.PivotTables("PivotTable1").PivotSelect "'Sum of Elapsed Time'", _
            xlDataAndLabel, True
        ActiveSheet.PivotTables("PivotTable1").DataPivotField.PivotItems( _
            "Sum of Elapsed Time").Caption = "Total Elapsed Time"
        ActiveSheet.PivotTables("PivotTable1").DataPivotField.PivotItems( _
            "Sum of Total Batch Items").Caption = "Total Batch Size"
            
            
        ActiveWorkbook.ShowPivotTableFieldList = False
        Application.ScreenUpdating = True
        
    End Sub
    I keep getting an error relating to PivotTable Properties when the codes gets to this portion of the code...
    ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
            "PivotTable1").PivotFields("Total Batch Items"), "Sum of Total Batch Items", _
            xlSum
        ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
            "PivotTable1").PivotFields("Elapsed Time"), "Sum of Elapsed Time", xlSum
        ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
            "PivotTable1").PivotFields("Expected Time"), "Sum of Expected Time", xlSum
        ActiveSheet.PivotTables("PivotTable1").CalculatedFields.Add _
            "Rate of Productivity", "='Expected Time' /'Elapsed Time'", True
        ActiveSheet.PivotTables("PivotTable1").PivotFields("Rate of Productivity"). _
            Orientation = xlDataField
    And I am going nuts trying to resolve. Can anyone please give me some insight or assistance to resolve this issue?

  2. #2
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Can't resolve PivotTable Property error.

    What is actual error?

    I will suggest you continue to use PVT variable:
    Sub CreatePivotTable()
    
        Dim WSD As Worksheet
        Dim PTCache As PivotCache
        Dim PVT As PivotTable
        Dim PRange As Range
        Dim FinalRow As Long
        Dim FinalCol As Long
        Dim PVTRows As Long
        Dim PVTCols As Long
        Dim NewRow As Long
        Dim WS As Worksheet
        
        
    
        Application.ScreenUpdating = False
        Set WSD = Worksheets("StratixTimeReport")
        Set WS = Worksheets("Report Summary")
        For Each PVT In WSD.PivotTables
            PVT.TableRange2.Clear
        Next PVT
            FinalRow = WSD.Cells(Application.Rows.Count, 1).End(xlUp).Row
            FinalCol = WSD.Cells(1, Application.Columns.Count).End(xlToLeft).Column
            Set PRange = WSD.Cells(1, 1).Resize(FinalRow, FinalCol)
            Set PTCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=PRange.Address)
            Set PVT = PTCache.CreatePivotTable(TableDestination:=WS.Cells(1, 1), TableName:="PivotTable1")
            
            With PVT
                .ManualUpdate = True
                With .PivotFields("Tech")
                    .Orientation = xlRowField
                    .Position = 1
                End With
                With .PivotFields("Product")
                    .Orientation = xlRowField
                    .Position = 2
                End With
            
                .AddDataField .PivotFields("Total Batch Items"), "Total Batch Size", xlSum
                .AddDataField .PivotFields("Elapsed Time"), "Total Elapsed Time", xlSum
                .AddDataField .PivotFields("Expected Time"), "Total Expected Time", xlSum
                .CalculatedFields.Add "Rate of Productivity", "='Expected Time' /'Elapsed Time'", True
                .PivotFields("Rate of Productivity").Orientation = xlDataField
    
                With .DataPivotField
                    .Orientation = xlColumnField
                    .Position = 1
                End With
                With .PivotFields("Sum of Rate of Productivity")
                    .NumberFormat = "0.00%"
                    .Caption = "Rate of Productivity"
                End With
                .PivotFields("Total Elapsed Time").NumberFormat = "0.00"
                .ShowTableStyleColumnStripes = True
                .ShowTableStyleRowStripes = True
                .TableStyle2 = "PivotStyleMedium6"
                .ColumnGrand = False
                .RowGrand = True
                .RowAxisLayout xlCompactRow
                .ManualUpdate = False
        
            End With
            
            
        ActiveWorkbook.ShowPivotTableFieldList = False
        Application.ScreenUpdating = True
        
    End Sub
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  3. #3
    Forum Contributor
    Join Date
    05-13-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    378

    Re: Can't resolve PivotTable Property error.

    I was getting the following error....

    "Run-time error '1004':
    Unable to get the PivotTable property of the Worksheet class"

    And I am getting that error every time the code gets to this portion...
    ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
            "PivotTable1").PivotFields("Total Batch Items"), "Sum of Total Batch Items", _
            xlSum
        ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
            "PivotTable1").PivotFields("Elapsed Time"), "Sum of Elapsed Time", xlSum
        ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
            "PivotTable1").PivotFields("Expected Time"), "Sum of Expected Time", xlSum
        ActiveSheet.PivotTables("PivotTable1").CalculatedFields.Add _
            "Rate of Productivity", "='Expected Time' /'Elapsed Time'", True
        ActiveSheet.PivotTables("PivotTable1").PivotFields("Rate of Productivity"). _
            Orientation = xlDataField
    So if I use your amended code, then that should resolve this issue?

  4. #4
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Can't resolve PivotTable Property error.

    You may try it and tell me.

  5. #5
    Forum Contributor
    Join Date
    05-13-2012
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    378

    Re: Can't resolve PivotTable Property error.

    Nice!!!

    Awesome!!!! Thanks...it works like a charm now.

  6. #6
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Can't resolve PivotTable Property error.

    You are welcome.

+ 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': Unable to get the PivotFields property of the PivotTable class
    By jaimeteele in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-13-2013, 05:43 PM
  2. Unable to get the PivotFields property of the PivotTable Class
    By ajmarti82 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-17-2013, 04:40 PM
  3. [SOLVED] Excel run-time error '381': Could not set the List property. Invalid property array index
    By eemiller1997 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-20-2012, 12:48 PM
  4. Unable to get the RowRange property of the PivotTable class
    By dan_coder in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-02-2006, 04:13 AM
  5. Unable to get the PivotFields property of the PivotTable Class
    By Karl in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-25-2006, 02:20 PM

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