清除Power Pivot表Excel VBA中的所有值字段

时间:2019-03-29 14:05:20

标签: excel vba

我要清除力量数据透视表中的所有字段

 Sub RemoveValueFields()
    Dim pt As PivotTable
    Dim pf As PivotField
    Dim df As PivotField

    Set pt = ActiveSheet.PivotTables("Invoices")

    'remove calculated fields first,
    'if any exist
    For Each pf In pt.CalculatedFields
        For Each df In pt.DataFields
          If df.SourceName = pf.Name Then
            With df
              .Parent.PivotItems(.Name) _
                .Visible = False
            End With
            Exit For
                  End If
Next df
    Next pf

    For Each pf In pt.DataFields
      pf.Orientation = xlHidden 'I get an error here Unable to set the Orientation property of the PivotField class
    Next pf

 End Sub

我在字段中找到了此答案:How to remove all column fields in a Pivot Table ( Power Pivot)? 但不确定如何将其适应“值字段” ...

0 个答案:

没有答案