+ Reply to Thread
Results 1 to 19 of 19

How to List details of Calculated Items and the Groups used in a Pivot Table using VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    How to List details of Calculated Items and the Groups used in a Pivot Table using VBA

    How to List details of Calculated Items and the Groups used in a Pivot Table using VBA

    Dear Forum,

    I found a code on the Internet which gives the information of the various fields in a Pivot Table as well as the Calculated Field in a Tabular Form, I tried researching for the information on Groups in a Pivot Table and Calculated Items but didn't find any code.Can some please help me with the same. I want to create a Table of Information of the existing Pivot Tables in Sheet with all the details including the Groups in a Pivot Table as well as the Calculated Field.

    In Groups , I have come across different Groups which we do normally , example certain Country Names i.e Text Values can be categorized as Continents , likewise certain Plain Numbers can be divided into groups using a Fixed Difference and the last one I know is that of Dates which can be grouped in Years Months and Quarters. SO I need to capture the information in a pivot table of any of these Groups which are used in the Pivot Table.

    Also, if there is a Calculated Item, capture the information of the Pivot Table Calculated Item along with the Formula and the Position and the Items used.


    I am attaching a Sample Data where someone can help me with the code

    I have 2 Groups one Group is Based on the Sales Column and the other is Dates.

    In the Sheet Data+Pivot I have a Pivot Table which has a Calculated item with the Name - 2Mon

    
    Sub LocList_ALL_PTs_PFs()
    'contextures.com
    'lists all pivot tables in
    ' active workbook
    'use the Notes column to
    ' add comments about fields
    Dim lRow As Long
    Dim ws As Worksheet
    Dim wsList As Worksheet
    Dim pt As PivotTable
    Dim pf As PivotField
    Dim df As PivotField
    Dim pi As PivotItem
    Dim lLoc As Long
    Dim lPos As Long
    Dim pfCount As Long
    Dim myList As ListObject
    Dim bOLAP As Boolean
    Application.DisplayAlerts = False
    
    On Error GoTo errHandler
    
    Set wsList = Sheets.Add
    lRow = 2
    
    With wsList
      .Cells(1, 1).Value = "Sheet"
      .Cells(1, 2).Value = "PT Name"
      .Cells(1, 3).Value = "PT Address"
      .Cells(1, 4).Value = "Caption"
      .Cells(1, 5).Value = "Heading"
      .Cells(1, 6).Value = "Source Name"
      .Cells(1, 7).Value = "Location"
      .Cells(1, 8).Value = "Position"
      .Cells(1, 9).Value = "Sample Item"
      .Cells(1, 10).Value = "Formula"
      .Cells(1, 11).Value = "OLAP"
      .Rows(1).Font.Bold = True
      
      For Each ws In ActiveWorkbook.Worksheets
        For Each pt In ws.PivotTables
          bOLAP = pt.PivotCache.OLAP
          
          For pfCount = 1 To pt.RowFields.Count
            Set pf = pt.RowFields(pfCount)
            lLoc = pf.Orientation
            If pf.Caption <> "Values" Then
            .Cells(lRow, 1).Value = ws.Name
            .Cells(lRow, 2).Value = pt.Name
            .Cells(lRow, 3).Value = pt.TableRange2.Address
            .Cells(lRow, 4).Value = pf.Caption
            .Cells(lRow, 5).Value = pf.LabelRange.Address
            .Cells(lRow, 6).Value = pf.SourceName
            .Cells(lRow, 7).Value = lLoc & " - Row"
            .Cells(lRow, 8).Value = pfCount
              On Error Resume Next
              If pf.PivotItems.Count > 0 _
                And bOLAP = False Then
                .Cells(lRow, 9).Value _
                    = pf.PivotItems(1).Value
              End If
              On Error GoTo errHandler
            .Cells(lRow, 11).Value = bOLAP
              lRow = lRow + 1
              lLoc = 0
            End If
          Next pfCount
          
          For pfCount = 1 To pt.ColumnFields.Count
            Set pf = pt.ColumnFields(pfCount)
            lLoc = pf.Orientation
            If pf.Caption <> "Values" Then
            .Cells(lRow, 1).Value = ws.Name
            .Cells(lRow, 2).Value = pt.Name
            .Cells(lRow, 3).Value = pt.TableRange2.Address
            .Cells(lRow, 4).Value = pf.Caption
            .Cells(lRow, 5).Value = pf.LabelRange.Address
            .Cells(lRow, 6).Value = pf.SourceName
            .Cells(lRow, 7).Value = lLoc & " - Column"
            .Cells(lRow, 8).Value = pfCount
              On Error Resume Next
              If pf.PivotItems.Count > 0 _
                And bOLAP = False Then
                .Cells(lRow, 9).Value _
                    = pf.PivotItems(1).Value
              End If
              On Error GoTo errHandler
            .Cells(lRow, 11).Value = bOLAP
              lRow = lRow + 1
              lLoc = 0
            End If
          Next pfCount
          
          For pfCount = 1 To pt.PageFields.Count
            Set pf = pt.PageFields(pfCount)
            lLoc = pf.Orientation
            .Cells(lRow, 1).Value = ws.Name
            .Cells(lRow, 2).Value = pt.Name
            .Cells(lRow, 3).Value = pt.TableRange2.Address
            .Cells(lRow, 4).Value = pf.Caption
            .Cells(lRow, 5).Value = pf.LabelRange.Address
            .Cells(lRow, 6).Value = pf.SourceName
            .Cells(lRow, 7).Value = lLoc & " - Filter"
            .Cells(lRow, 8).Value = pfCount
            On Error Resume Next
              If pf.PivotItems.Count > 0 _
                And bOLAP = False Then
              .Cells(lRow, 9).Value _
                  = pf.PivotItems(1).Value
            End If
            On Error GoTo errHandler
            .Cells(lRow, 11).Value = bOLAP
            lRow = lRow + 1
            lLoc = 0
          Next pfCount
          
          For pfCount = 1 To pt.DataFields.Count
            Set pf = pt.DataFields(pfCount)
            lLoc = pf.Orientation
            
            Set df = pt.PivotFields(pf.SourceName)
            .Cells(lRow, 1).Value = ws.Name
            .Cells(lRow, 2).Value = pt.Name
            .Cells(lRow, 3).Value = pt.TableRange2.Address
            .Cells(lRow, 4).Value = df.Caption
            .Cells(lRow, 5).Value = _
                  pf.LabelRange.Cells(1).Address
           .Cells(lRow, 6).Value = df.SourceName
            .Cells(lRow, 7).Value = lLoc & " - Data"
    
            .Cells(lRow, 8).Value = pfCount
            'sample data not shown for value fields
            On Error Resume Next
              'print formula for calculated fields
              '.Cells(lRow, 6).Value = " " & pf.Formula
                If df.IsCalculated = True Then
                  .Cells(lRow, 10).Value = _
                      Right(df.Formula, Len(df.Formula) - 1)
                End If
            On Error GoTo errHandler
             .Cells(lRow, 11).Value = bOLAP
           lRow = lRow + 1
            lLoc = 0
            Set df = Nothing
          Next pfCount
                
        Next pt
      Next ws
      .Columns("A:K").EntireColumn.AutoFit
      Set myList = .ListObjects.Add(xlSrcRange, _
          Range("A1").CurrentRegion)
    
    End With
    MsgBox "Done"
    
    exitHandler:
        Application.DisplayAlerts = True
        Exit Sub
    errHandler:
        MsgBox "Could not create list"
        Resume exitHandler
    
    End Sub
    Attached Files Attached Files
    Last edited by e4excel; 06-20-2020 at 03:19 PM.

  2. #2
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: How to List details of Calculated Items and the Groups used in a Pivot Table using VBA

    In my attached file the Names have not been Grouped but if they were then how do I get the information for this Row Label Group.

  3. #3
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: How to List details of Calculated Items and the Groups used in a Pivot Table using VBA

    Bump A Thread

  4. #4
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: How to List details of Calculated Items and the Groups used in a Pivot Table using VBA

    Can someone please help me as I have to work on almost 50+ Piovt Tables and want to create an Information Table of all these Pivot Tables used in a single File.

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2406 Win 11 Home 64 Bit
    Posts
    24,035

    Re: How to List details of Calculated Items and the Groups used in a Pivot Table using VBA

    Are you still using Excel 2007? Or a later version? If later, please update your profile as there may be more options available to you if we know which version of excel you are using.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  6. #6
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: How to List details of Calculated Items and the Groups used in a Pivot Table using VBA

    I am using 2010 and 2007 at work

  7. #7
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: How to List details of Calculated Items and the Groups used in a Pivot Table using VBA

    As mentioned Excel 2007 and 2010, can you please suggest some codes in regards with the query. That would be really helpful.

  8. #8
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: How to List details of Calculated Items and the Groups used in a Pivot Table using VBA

    Bump a Thread

  9. #9
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: How to List details of Calculated Items and the Groups used in a Pivot Table using VBA

    Bump A Thread

  10. #10
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: How to List details of Calculated Items and the Groups used in a Pivot Table using VBA

    Please can someone help me on this..

  11. #11
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2406 Win 11 Home 64 Bit
    Posts
    24,035

    Re: How to List details of Calculated Items and the Groups used in a Pivot Table using VBA

    You have four sheets, yet no explanation as to which is raw data, which is an example of your final solution. I suspect that you have not received any help as you are not clear in your explanation as to what each sheet does or is expected to do. While all this may be clear inside your head, it is actually very foggy to me.

    Suggest you explain each sheet starting with your raw data and what you want to happen. Finally, show us and explain which sheet is your mocked up solution. Keep bumping with no further explanations and I am sure that you will not get an answer. Help us to help you by explaining in more detail using your samples in the explanation.

  12. #12
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: How to List details of Calculated Items and the Groups used in a Pivot Table using VBA

    HI Alan,

    You are probably right, I actually have given a code which lists all the details of the pivot table elements except for the Calculated Items and Groups in a pivot table.So the code mentioned in the first codes is the analogy or the way in which I need to get the Calculated Items information listed likewise I need the information for any Groups used in a Pivot table for which I have 2 SHeets Group Data with the Groupings and the Data + Pivot with a Calculated Item example.
    My expectation is to get the details of the Group and Calculated Items in these Pivot Tables or any Pivot Tables.

    Thanks in advance

  13. #13
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: How to List details of Calculated Items and the Groups used in a Pivot Table using VBA

    Bump A Thread..

    I want to get the Calculated Items - YES or NO in a Column, Base Field and Child Field in different Columns and then the Calculated Items formula used.
    Likewise I need to get the Group -Start and End Details and the Field used. Ex : - Date as Source Data then Grouped by Quarters.
    Last edited by e4excel; 07-07-2020 at 04:49 AM.

  14. #14
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: How to List details of Calculated Items and the Groups used in a Pivot Table using VBA

    Bump A Thread.

    In my File I have given Raw Data and a Pivot Table with Grouped Example and one with Calcullated Item. I want someone to help me with a VBA code which will give the Calculated Item if present in a Pivot Table list its details such as Child and Base Field and the formula used..
    Similarly in the Pivot table with the Grouping I need to list the details of the Pivot Table with a VBA Code.

    Hope this helps to understand my requirement...For that I have added a code which I found on the net which lists Pivot table details except for Calculated Items and Grouping information

  15. #15
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: How to List details of Calculated Items and the Groups used in a Pivot Table using VBA

    Please someone help me now I have given all the information I could possibly think of...

  16. #16
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: How to List details of Calculated Items and the Groups used in a Pivot Table using VBA

    I am still looking for help on this, When I run this Macro I get the details
    Call LocList_ALL_PTs_PFs
    Similarly I need some code which can help me on Calculated Item and Grouping.

  17. #17
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: How to List details of Calculated Items and the Groups used in a Pivot Table using VBA

    Bump A thread

  18. #18
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: How to List details of Calculated Items and the Groups used in a Pivot Table using VBA

    Can someone offer some suggestion of not a solution

  19. #19
    Registered User
    Join Date
    11-03-2008
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    2,521

    Re: How to List details of Calculated Items and the Groups used in a Pivot Table using VBA

    Wish somesone replies on this Thread so many Views but no response..Please can someone help me on this...

+ 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. Pivot Table - Calculated Field on two groups of columns
    By swilson2006 in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 12-21-2018, 06:18 PM
  2. Calculated fields and items rules in Pivot Table
    By hristina.trpkova in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-27-2018, 02:22 AM
  3. Replies: 0
    Last Post: 08-09-2006, 03:40 AM
  4. [SOLVED] Calculated Items in Pivot Table
    By Craig in forum Excel General
    Replies: 1
    Last Post: 02-27-2006, 08:35 PM
  5. Replies: 1
    Last Post: 02-09-2005, 12:06 AM
  6. Pivot Table - Calculated Items
    By bchan in forum Excel General
    Replies: 0
    Last Post: 01-17-2005, 10:31 PM
  7. Pivot Table - Calculated Items
    By bchan in forum Excel General
    Replies: 0
    Last Post: 01-17-2005, 03:00 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