text 如何快速将所有数据透视表对齐到同一个数据透视表缓存?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 如何快速将所有数据透视表对齐到同一个数据透视表缓存?相关的知识,希望对你有一定的参考价值。

Sub Allign_Source_Data()

Dim Wks As Worksheet
Dim PT As PivotTable
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Application.DisplayAlerts = False

'The code below can also change the pivot table source from interanl (e.g. dataset in wbk)
                                                        'to external (e.g OLEDB, ODBC connection)

For Each Wks In ActiveWorkbook.Worksheets
    Wks.Activate

    For Each PT In ActiveSheet.PivotTables
    
        PT.CacheIndex = Sheets(1).PivotTables(1).CacheIndex
        '1 in Sheets(1) refers to the position of the sheet in the wbk
        '1 in PivotTables(1) refers to the first pivot table in the active worksheet
        
        PT.RefreshTable
        
    Next PT
Next Wks

Application.DisplayAlerts = True
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~------
'The code above could generate error messages if:
        '1) a worksheet has multiple pivot tables in it
        '2) the workbook and/or worksheets are password-protected

End Sub

以上是关于text 如何快速将所有数据透视表对齐到同一个数据透视表缓存?的主要内容,如果未能解决你的问题,请参考以下文章

text 如何刷新工作簿中的所有数据透视表?

Excel数据透视表(图)的切片器,快速筛选数据表格与可视化!

取消透视 Excel 矩阵/数据透视表?

在 Laravel 4 中查询数据透视表

快速取消数据透视表的分类汇总行和总计行

如何将一个Excel表中有用的数据导入到另一个表中去?