+ Reply to Thread
Results 1 to 2 of 2

DataFields and RowFields not appearing in PT

Hybrid View

  1. #1
    Registered User
    Join Date
    07-10-2012
    Location
    FL
    MS-Off Ver
    Excel 2007
    Posts
    17

    DataFields and RowFields not appearing in PT

    Attempting to create a PT with 3 rowfields and 2 datafields. PT is created, but nothing else works. The more changes I made the worse it gets. At the point where I've lost the basic logic of a PT.

    
    Sub MakePTReport()
    
    '   This PT summarizes personnel budget estimates by Program,
    '   Subprogram and account; the number of FTE Positions and
    '   their associated costs.
        
        Dim PT As PivotTable
        Dim PF As PivotField
        Dim CacheOfPT As PivotCache
        Dim ptLastRow As Long
    
    'Screen Updating
        Application.ScreenUpdating = False
        
    'If pivot table exists delete it
        On Error Resume Next
        Sheets("PTreport").Select
        ActiveSheet.PivotTables("CostPT").TableRange2.Clear
    
    'Set the cache of PT
        Sheets("Summary of Data").Select
        Range("A1").Select
        ptLastRow = ActiveSheet.UsedRange.Rows.Count
        Set CacheOfPT = ActiveWorkbook.PivotCaches.Create(xlDatabase, Range("A1:H" & ptLastRow))
    
    'Create the Pivot Table
        Sheets("PTreport").Select
        Set PT = ActiveSheet.PivotTables.Add(CacheOfPT, Range("A3"), "CostPT")
    
    'Put in fields
        With PF
            .PivotFields ("Program")
            .Orientation = xlRowField
            .Position = 1
        End With
        With PF
            .PivotFields ("Sub-Program")
            .Orientation = xlRowField
            .Position = 2
        End With
        With PF
            .PivotFields ("Line Seq Descrpition")
            .Orientation = xlRowField
            .Position = 3
        End With
        With PF
            .PivotFields ("FTE")
            .Orientation = xlDataField
            .NumberFormat = "##0.00"
        End With
        With PF
            .AddDataField ActiveSheet.PivotTables( _
            "CostPT")
           ' .PivotFields ("FTE"), "Total FTE", xlSum
        End With
        With PF
            .AddDataField ActiveSheet.PivotTables( _
             "CostPT").PivotFields("Cost"), "Total Cost", xlSum
        End With
        
    'Display PT in Classic View
         With PT
            .RowAxisLayout xlTabularRow
        End With
        
    'Screen Updating
        Application.ScreenUpdating = True
    
    End Sub

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: DataFields and RowFields not appearing in PT

    Is this solved?

    If you solve a problem yourself before anyone else has responded, please take a moment to describe your solution, chances are some other member will benefit.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ Reply to Thread

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