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

text
阅读 68 收藏 0 点赞 0 评论 0

ForEachPT_allign_to_the_same_cache.bas
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号