我要清除力量数据透视表中的所有值字段
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)? 但不确定如何将其适应“值字段” ...