Abaixo seguem alguns código que facilitam a manipulação dos dados contidos em nossas Tabelas Dinâmicas (Pivot Tables).
ATUALIZANDO UMA TABELA DINÂMICA SIMPLES (Refresh a Single Pivot Table):
Sub SetupPivot()
Dim nPT As PivotTable
Set nPT = ActiveSheet.PivotTables("PT001")
nPT.RefreshTable
End Sub
ATUALIZANDO TODAS AS TABELAS DINÂMICAS NUMA WOKSHEET (Refresh all Pivot Tables in a Worksheet):
Sub SetupAllPivotsWorksheet()
Dim nPT As PivotTable
For Each nPT In ActiveSheet.PivotTables
nPT.RefreshTable
Next nPT
End Sub
ATUALIZANDO TODAS AS TABELAS DINÂMICAS PRÉ-SELCIONADAS NUMA WOKSHEET (Refresh Chosen Pivot Tables in a Worksheet):
Sub AllChosenPivotswSheet()
Dim nPT As PivotTable
For Each nPT In ActiveSheet.PivotTablesATUALIZANDO TODAS AS TABELAS DINÂMICAS PRÉ-EXISTENTES NUM WORKBOOK (Refresh All Chosen Pivot Tables in a Workbook):
Select Case nPT.Name
Case "PT001", "PT005", "PT009"
nPT.RefreshTable
Case Else
End Select
Next pt
End Sub
Sub AllChosenPivotswBook()ATUALIZANDO TODAS AS QUERYTABLES PRÉ-EXISTENTES NUM WORKBOOK (Refresh All QueryTable instead):
Dim nPT As PivotTable
Dim nWS As Worksheet
For Each nWS In ActiveWorkbook.Worksheets
For Each nPT In nWS.PivotTables
nPT.RefreshTable
Next nPT
Next nWS
End Sub
Sub AllChosenPivotswBook()For Each nWS In ActiveWorkbook.Worksheets
Dim qryTbl As QueryTable
Dim nWS As Worksheet
For Each qryTbl In nWS.QueryTables
qryTbl.Refresh BackgroundQuery:=False
Next qryTbl
Next nWS
End Sub
ATUALIZA TODAS AS TABELAS DINÂMICAS NUMA WOKSHEET QUANDO ESTA FOR ALTERADA (Automatically refresh pivot table when data in a sheet changes in Excel): Baixe planilha para teste.
Private Sub Worksheet_Calculate()
'Caso alguma informação mude na worksheet, a Tabela Dinâmica será atualizada.
Sheets("PT001").PivotTables("PivotTable001").RefreshTable
End Sub
A&A - WORK, DON´T PLAY!
http://al-bernardes.sites.uol.com.br/
bernardess@gmail.com
Twitter: @officespecialis
@brzexceldevelop
@brzaccessdevel