Search code examples
excelvbarefresh

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


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?


Solution

  • Yes.

    ThisWorkbook.RefreshAll
    

    Or, if your Excel version is old enough,

    Dim Sheet as WorkSheet, Pivot as PivotTable
    For Each Sheet in ThisWorkbook.WorkSheets
        For Each Pivot in Sheet.PivotTables
            Pivot.RefreshTable
            Pivot.Update
        Next
    Next