简体   繁体   中英

Finding lost PivotTables in Microsoft Excel

In Microsoft Excel, when refreshing my data sources (clicking "Refresh All" in the "Connections" block under the "Data" tab), it provides me with a message saying that it can't find the data source for a PivotTable - this is understandable, as I deleted the Sheet that contained the data.

The problem is now finding the specific PivotTable to delete it, as I don't want to receive the message every time I refresh my data sources.

Any ideas?

As a simple, one-off test, I think this will work for you. It displays a message and selects the offending pivot table. Just put this code in a module in the workbook with the pivot tables:

Sub FindDatalessPivot()
Dim ws As Excel.Worksheet
Dim pt As Excel.PivotTable

For Each ws In ThisWorkbook.Worksheets
    For Each pt In ws.PivotTables
        With pt
            On Error Resume Next
            .RefreshTable
            If Err.Number <> 0 Then
                ws.Activate
                .DataBodyRange.Select
                MsgBox .Name & " in " & ws.Name & " is disconnected."
            End If
            On Error GoTo 0
        End With
    Next pt
Next ws
End Sub

Of course, you could do this by hand as well, by refreshing each pivot table individually.

I also note, that at least in Excel 2010, when I Refresh All a dialog pops up telling me which pivot table isn't connecting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM