Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in


How to list all pivot tables from a workbook?

Supposing you have a large workbook which contains multiple pivot tables, now, you want to list all the pivot tables in this workbook, is it possible? Of course, the following VBA code in this article will do you a favor. To know more details, please read the below article.

List all pivot tables from a workbook with VBA code

arrow blue right bubble List all pivot tables from a workbook with VBA code

The following VBA code can help you to list all the pivot table names along with their attributes, such as source data range, worksheet name, refreshed date and so on.

1. Open your workbook that you want to list all the pivot tables.

2. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.

3. Click Insert > Module, and paste the following code in the Module Window.

VBA code: List all pivot tables from a workbook

Sub ListPivotsInfor()
'Update 20141112
    Dim St As Worksheet
    Dim NewSt As Worksheet
    Dim pt As PivotTable
    Dim I, K As Long
    Application.ScreenUpdating = False
    Set NewSt = Worksheets.Add
    I = 1: K = 2
    With NewSt
        .Cells(I, 1) = "Name"
        .Cells(I, 2) = "Source"
        .Cells(I, 3) = "Refreshed by"
        .Cells(I, 4) = "Refreshed"
        .Cells(I, 5) = "Sheet"
        .Cells(I, 6) = "Location"
        For Each St In ActiveWorkbook.Worksheets
            For Each pt In St.PivotTables
                I = I + 1
                .Cells(I, 1).Value = pt.Name
                .Cells(I, 2).Value = pt.SourceData
                .Cells(I, 3).Value = pt.RefreshName
                .Cells(I, 4).Value = pt.RefreshDate
                .Cells(I, 5).Value = St.Name
                .Cells(I, 6).Value = pt.TableRange1.Address
    End With
    Application.ScreenUpdating = True
End Sub

4. Then press F5 key to run this code, all the pivot table names, source data range, worksheet name and other attributes are listed in a new worksheet which placed in the front of your active worksheet as following screenshot shown:


Related articles:

How to check if a pivot table exists in a workbook?

How to add multiple fields into pivot table?

Recommended Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 71%, and Help You To Stand Out From Crowd!

Would you like to complete your daily work quickly and perfectly? Kutools For Excel brings 300+ cool and powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) for 1500+ work scenarios, helps you solve 82% Excel problems.

  •  Deal with all complicated tasks in seconds, help to enhance your work ability, get success from the fierce competition, and never worry about being fired.
  •  Save a lot of work time, leave much time for you to love and care the family and enjoy a comfortable life now.
  •  Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands, and give you a healthy body.
  •  Become an Excel expert in 3 minutes, and get admiring glance from your colleagues or friends.
  •  No longer need to remember any painful formulas and VBA codes, have a relaxing and pleasant mind, give you a thrill you've never had before.
  •  Spend only $39, but worth than $4000 training of others. Being used by 110,000 elites and 300+ well-known companies.
  •  60-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years. Buy once, use forever.
  •  Change the way you work now, and give you a better life immediately!

Office Tab Brings Efficient And Handy Tabs to Office (include Excel), Just Like Chrome, Firefox, And New IE

  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Open and create documents in new tabs of same window, rather than in new windows.
  • Help you work faster and easily stand out from the crowd! One second to switch between dozens of open documents!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Abraham Garzon · 1 months ago
    This is awesome! I have been looking for a code like this one, but with the addition of showing all active fields per table. I need to clean up the source tables from unnecessary fields (too heavy) and they feed a book of over 300 pivots. I'd prefer not to go one pivot table at a time to figure out which fields I can eliminate... If you could show me how, it would be incredible... Thanks!
  • To post as a guest, your comment is unpublished.
    Vinicius · 1 months ago
    Amazing!!! thksss!!!!
  • To post as a guest, your comment is unpublished.
    Mark · 1 years ago
    Saved me from a major headache!
    Couldn't find what pivot table was causing a "Refresh All Error"
    Boom Listed with locations, Thank you so much
  • To post as a guest, your comment is unpublished.
    chris · 1 years ago
    For Connection Only info the Data connection info isa property of the PivotCache
    I have a workbook that has over 40 pivot tables with a mix of Excel Tables and SQL server Data Connections. I use the following code to keep track of them

    Sub GetPivotTableInfo()

    Dim wb As Workbook
    Dim pvt As PivotTable
    Dim wsheet As Worksheet
    Dim pc As PivotCache

    Set wb = ActiveWorkbook
    For Each wsheet In wb.Worksheets
    For Each pvt In wsheet.PivotTables
    Debug.Print wsheet.Name & ": " & pvt.Name
    Set pc = wb.PivotCaches(pvt.CacheIndex)
    If pc.SourceType = xlDatabase Then
    Debug.Print pc.SourceData
    If pc.QueryType = xlOLEDBQuery Then
    Debug.Print pc.Connection
    Debug.Print pc.SourceConnectionFile
    Debug.Print pc.WorkbookConnection.Name
    Debug.Print pc.CommandText
    End If
    End If

    Next pvt
    Next wsheet
  • To post as a guest, your comment is unpublished.
    Turnabout · 1 years ago
    Very powerful. Thanks so much.