我有一个通过数据透视图显示的仪表板。通过宏更新源数据。但是,当我刷新数据透视表的数据时,源数据表会缩减为源文件的标题吗?有没有一种方法可以刷新这些数据透视表,而不必每次通过运行宏来更新源工作表时都选择源数据?
答案 0 :(得分:1)
如果您只需要刷新数据透视表,则可以仅出于此原因添加新的子项。这是一个示例:
Sub RefreshPivotTable()
Dim ws As Worksheet 'Sheet containing the pivot table
Dim rng As Range 'top left cell of the pivot table
Dim pt As PivotTable
Set ws = Worksheets("Pivot Cohort")
Set rng = ws.Range("G1")
Set pt = rng.PivotTable
'~~> Refresh only this pivot table
pt.RefreshTable
'~~> Or Refresh all tables and queries in the active workbook
ActiveWorkbook.RefreshAll
'~~> Clear the variables from memory
Set ws = Nothing
Set rng = Nothing
Set pt = Nothing
End Sub