How can I locate Pivot tables in a workbook

AndyDevine1

Board Regular
Joined
Jun 1, 2006
Messages
172
hi there

There is code to update pivot tables in a workbook I've inherited

Running this is causing an error as the tables cannot locate the source data

I've gone through the many pivot tables and re-pointed them to the correct data source

When I re-run the code it is still telling me there are some pivot tables where the data source cannot be found.

I've no hidden worksheets

Is there a way I can locate the remaining pivot tables in order to fix the problem?

Many thanks
 
Thank you - this helped me locate a generically-named pivot table within 3 tabs of dozens of pivots!
In normal case of pivot tables based on cell-ranges this piece of code works. However, when a pivot table is based on a data model, the code throws the error: 1004-object not defined. What is the remedy? In fact, the pivottable.Sourcedata fails when it encounters a data model.
 
Upvote 0

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
I haven't posted here in ages... but try this:

VBA Code:
Sub PivotID()
    Dim wb As Workbook
    Dim sh As Worksheet
    Dim pt As PivotTable
    Dim ptSource As String
    
    Set wb = ActiveWorkbook
    
    For Each sh In wb.Worksheets
        MsgBox sh.Name & " has " & sh.PivotTables.Count & " pivot tables"
        If sh.PivotTables.Count > 0 Then
            For Each pt In sh.PivotTables
                If pt.DataModelTable Is Nothing Then
                    ptSource = pt.SourceData
                Else
                    ptSource = "Data Model: " & pt.DataModelTable.Name
                End If
                
                MsgBox pt.Name & " source data is " & ptSource
            Next
        End If
    
    Next

End Sub
 
Upvote 0
I haven't posted here in ages... but try this:

VBA Code:
Sub PivotID()
    Dim wb As Workbook
    Dim sh As Worksheet
    Dim pt As PivotTable
    Dim ptSource As String
   
    Set wb = ActiveWorkbook
   
    For Each sh In wb.Worksheets
        MsgBox sh.Name & " has " & sh.PivotTables.Count & " pivot tables"
        If sh.PivotTables.Count > 0 Then
            For Each pt In sh.PivotTables
                If pt.DataModelTable Is Nothing Then
                    ptSource = pt.SourceData
                Else
                    ptSource = "Data Model: " & pt.DataModelTable.Name
                End If
               
                MsgBox pt.Name & " source data is " & ptSource
            Next
        End If
   
    Next

End Sub
Thank you for your response. Upon execution of the code you provided, an error is encountered: "Run-time error '438': Object doesn't support this property or method."; the error pointed to the line = "
If pt.DataModelTable Is Nothing Then
Anyway, I have the best code available at this point which would at least provide me Source Data info for normal pivots which are not based on data model.
 
Upvote 0

Forum statistics

Threads
1,215,239
Messages
6,123,817
Members
449,127
Latest member
Cyko

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top