Ho una cartella di lavoro con 20 diverse tabelle pivot. C'è un modo semplice per trovare tutte le tabelle pivot e aggiornarle in VBA?
Sì.
ThisWorkbook.RefreshAll
Oppure, se la tua versione di Excel è abbastanza vecchia,
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
Questo codice VBA aggiornerà tutte le tabelle/carte pivot nella cartella di lavoro.
Sub RefreshAllPivotTables()
Dim PT As PivotTable
Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
For Each PT In WS.PivotTables
PT.RefreshTable
Next PT
Next WS
End Sub
Un'altra opzione non programmatica è:
Questo aggiornerà la tabella pivot ogni volta che la cartella di lavoro viene aperta.
Avete una collezione PivotTables su un oggetto VB Worksheet. Quindi, un ciclo veloce come questo funzionerà:
Sub RefreshPivotTables()
Dim pivotTable As PivotTable
For Each pivotTable In ActiveSheet.PivotTables
pivotTable.RefreshTable
Next
End Sub
Note dalla trincea:
Buona fortuna!