Excel数据透视表(VBA)将所有字段值更改为计数数字

时间:2018-05-07 18:49:07

标签: excel vba

我有这个VBA marco,它将所有字段值更改为Product。

  Dim pt As PivotTable
  Dim pf As PivotField
  Dim ws As Worksheet

  Set ws = ActiveSheet
  Set pt = ws.PivotTables(1)
  Application.ScreenUpdating = False

    pt.ManualUpdate = True
    For Each pf In pt.DataFields
      pf.Function = xlProduct
    Next pf
    pt.ManualUpdate = False

  Application.ScreenUpdating = True
  Set pf = Nothing
  Set pt = Nothing
  Set ws = Nothing
    End Sub

当我尝试将xlProduct更改为xlCount.Numbers时,代码不起作用。知道如何解决这个问题吗?