質問

Can someone tell me how I can find all the pivot tables in a workbook (or sheet)? In some cases a pivot table might be hidden or hard to find in a very large excel sheet. If i could at least get the cell address or range of where the pivot table(s) are/is, that would be great.

Thanks.

役に立ちましたか?

解決

This should work for you. It prints out the results to the Immediate window:

Sub FindPivotTables()
    Dim wst As Worksheet
    Dim pvt As PivotTable
    ' loop through all sheets and print name & address of all pivot tables
    For Each wst In ActiveWorkbook.Worksheets
        For Each pvt In wst.PivotTables
            Debug.Print wst.Name, pvt.TableRange2.Address, pvt.Name
        Next pvt
    Next wst
End Sub

他のヒント

Each worksheet should expose a PivotTables collection; you can loop through each worksheet looking for sheets that have a .PivotTables.Count > 0 and then loop through the PivotTables on that sheeet to find the one you are looking for:

Sub Test()

    Dim pTable As pivotTable

    Dim ws As Worksheet

    For Each ws In ActiveWorkbook.Worksheets

        Dim pivotTableCount

        pivotTableCount = ws.PivotTables.Count

        If pivotTableCount > 0 Then

            For Each pTable In ws.PivotTables

                 Dim pivotTableName As String
                 pivotTableName = pTable.Name

                 Dim pivotTableTopLeftCell As String
                 pivotTableTopLeftCell = pTable.Location

            Next pTable 

        End If



    Next ws


End Sub
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top