Refreshing all the pivot tables in my excel workbook with a macro

前端 未结 10 1334
长发绾君心
长发绾君心 2020-11-29 20:32

I have a workbook with 20 different pivot tables. Is there any easy way to find all the pivot tables and refresh them in VBA?

10条回答
  •  渐次进展
    2020-11-29 20:45

    The code

    Private Sub Worksheet_Activate()
        Dim PvtTbl As PivotTable
            Cells.EntireColumn.AutoFit
            For Each PvtTbl In Worksheets("Sales Details").PivotTables
            PvtTbl.RefreshTable
            Next
    End Sub 
    

    works fine.

    The code is used in the activate sheet module, thus it displays a flicker/glitch when the sheet is activated.

提交回复
热议问题