+ Reply to Thread
Results 1 to 2 of 2

Pivot Table Rows not getting listed with Excel VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    12-05-2013
    Location
    Newyork
    MS-Off Ver
    Excel 2013
    Posts
    6

    Pivot Table Rows not getting listed with Excel VBA

    I have the following requirement where I need to create the pivot table.

    1) The issue is when I execute the macro its successfully completed, but the Rows are not refreshed in the table. But if I execute step by step in edit mode, I'm getting the required output.

    2) 1st time when I run the macro its giving " Run time error 1004", but second time its running fine

    The input and the code are attachment with it

    Private Sub Execute1_Click()
    
    Dim WST As Worksheet, WSD As Worksheet
    Dim PTCache As PivotCache
    Dim pt As PivotTable
    Dim objChart As ChartObject
    Dim PRange As Range, rngChart As Range
    Dim FinalRow As Long, Finalcol As Long
       
    Set WSD = ThisWorkbook.Worksheets("sheet1")
    Set WST = ThisWorkbook.Worksheets("sheet2")
    
    ' Delete any previous Pivot able
    For Each pt In WST.PivotTables
        pt.TableRange2.Clear
    Next pt
    
    For Each chtObj In WST.ChartObjects
        chtObj.Delete
    Next
    'Define Input area and set up pivot Cache
    
    FinalRow = WSD.Cells(Rows.Count, "B").End(xlUp).Row
    Finalcol = WSD.Cells(1, Columns.Count).End(xlToLeft).Column
    
    Set PRange = WSD.Cells(1, 1).Resize(FinalRow, Finalcol)
    
    Application.Goto ThisWorkbook.Worksheets("sheet1").Range("A1"), True
    
    Set PTCache = ThisWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=PRange.Address)
    Set pt = PTCache.CreatePivotTable(TableDestination:=WST.Range("A2"), TableName:="Table1")
    
    'Turn off Update while Building the table
    pt.ManualUpdate = True
    
    Application.Goto ThisWorkbook.Worksheets("sheet2").Range("A2"), True
    
    ' Set up the PageFields
    With pt.PivotFields("DM")
        .Orientation = xlPageField
        .Position = 1
    End With
    
    With pt.PivotFields("PM")
        .Orientation = xlPageField
        .Position = 1
    End With
    
    With pt.PivotFields("LOB")
        .Orientation = xlRowField
        .Position = 1
    End With
            
    With pt.PivotFields("Bus Score")
        .Orientation = xlDataField
        .Function = xlAverage
        .NumberFormat = "0.00"
        .Position = 1
        .Name = "Avg of Bus"
    End With
    
    With pt.PivotFields("Sys Score")
        .Orientation = xlDataField
        .Function = xlAverage
        .NumberFormat = "0.00"
        .Position = 2
        .Name = "Avg of Sys"
    End With
    
    With pt.PivotFields("Proc Score")
        .Orientation = xlDataField
        .Function = xlAverage
        .NumberFormat = "0.00"
        .Position = 3
        .Name = "Avg of Proc"
    End With
    
    End Sub

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Pivot Table Rows not getting listed with Excel VBA

    This is a duplicate post and as such does not comply with Rule 5 of our forum rules. This thread will now be closed, you may continue in your other thread.

    Please read the forum rules. This is the second infringement today.

    Thread Closed.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

+ 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. Excel Pivot table - to show the total on rows not working?
    By eiffel99 in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 09-28-2015, 12:52 PM
  2. Add rows to table based on PIVOT table - Excel 2010
    By Pettaylor in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 07-27-2015, 08:49 AM
  3. Excel VBA/Macro: Selecting Specific Columns and Rows in Pivot Table and Formatting
    By rarascon in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-20-2013, 03:50 PM
  4. How to re-order the columns and rows in a pivot table - Excel 2010
    By Mirisage in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 04-15-2013, 08:35 AM
  5. Excel 2007 : Pivot table: Commentfield or lock rows
    By Helgera in forum Excel General
    Replies: 2
    Last Post: 03-29-2012, 03:12 PM
  6. Excel 2007 : Excel Pivot Table - calculated rows???
    By richrip in forum Excel General
    Replies: 0
    Last Post: 03-30-2009, 05:18 PM
  7. [SOLVED] How do I remove items listed in a pivot table drop down list box
    By Hart165Hour in forum Excel General
    Replies: 3
    Last Post: 03-16-2005, 01:06 AM

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