重要说明:我的数据来自一个多维数据集,因此它不是“普通”数据透视表
我在多张图纸上都有数据透视表,这些数据透视表都连接到相同的多维数据集数据。我想做的是编写一个代码,将一种度量更改为另一种度量。我在枢纽分析表中要拥有的“选择”(Choice)位置,我想隐藏所有其他测量。这是我到目前为止的代码:
Sub ChangePivotDataField()
Dim sht As Worksheet
Dim pvt As PivotTable
Dim MField As String
Dim Choice As String
Choice = "Sales"
If Choice = "Sales" Then
MField = "Units Sales"
ElseIf Choice = "Sessions" Then
MField = "Sessions"
ElseIf Choice = "Page Views" Then
MField = "PageViews"
ElseIf Choice = "Units" Then
MField = "Units Ordered"
End If
For Each sht In ThisWorkbook.Worksheets
For Each pvt In sht.PivotTables
pvt.CubeFields( _
"[Measures].[Sum of Sessions]").Orientation = xlHidden
pvt.AddDataField ActiveSheet. _
pvt.CubeFields("[Measures].[Sum of " & MField & "]"), _
"Sum of " & MField & ""
Next pvt
Next sht
End Sub
任何帮助将不胜感激!
谢谢
CMike