Sub SumtoCount() Dim pt As PivotField ’定义变量pt为字段 Application.ScreenUpdating = False ’禁止刷新屏幕 For Each pt In Sheet1.PivotTables(1).DataFields ’For-Next循环语句。遍历Sheet1中数据透视表1所有的字段集合 With pt ’wWth-End With语句,简化VBA代码,减少引用对象的寻找速度 .Function = xlSum ’字段的数值方式设置为求和 .Caption = .SourceName & ' ' ’字段名称修改为数据源中的字段名 End With Next Application.ScreenUpdating = True ’开启屏幕刷新 |
|
来自: hercules028 > 《excel》