1
我想自動添加字段到已經創建的數據透視表。這些字段將是「期間1的總和」...「期間360的總和」。我已經有了1-60的時間,但是我錯過了61-360。手動拖放300次將是一件痛苦的事情。所以我寫了一個宏,但我得到的錯誤: 無法既然已經創建了數據透視表,以獲得透視字段類數據透視表展開「值」VBA
的支點項目性質(這是一個大表有許多格式的怪癖),我不不想改變任何事情。我只是想把期間加上period61-period360的值。
我附上我的代碼。任何人可以給我的幫助將非常感謝,因爲我不知道我做錯了什麼,我試圖不要太沮喪。
非常感謝您提前。
這裏是我的代碼:
'--------------------- Expand_Pivot_to_360M Macro-------------------'
Sub Expand_Pivot_to_360M()
' Setting Pivot field classes to the "unable to get pivot items property of the pivot field class" error
Sheets("Monthly Summary").Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields("universe")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("buckets_break")
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("pool_name")
.Orientation = xlRowField
.Position = 3
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("gl_company_code")
.Orientation = xlRowField
.Position = 4
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("LEP")
.Orientation = xlRowField
.Position = 5
End With
循環展開Pivit 360期
' Using a Loop to Expand Pivot for 360 periods
Dim i As Integer
For i = 61 To 360 ' start at period 61 since periods 1 to 60 already include in pivot
Sheets("Monthly Summary").Select
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables(_
"PivotTable1").PivotFields("Period_i"), "Sum of Period_i", xlSum
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Sum of Period_i")
.Caption = "Count of Period_i"
.Function = xlCount
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Count of Period_i")
.Caption = "Sum of Period_i"
.Function = xlSum
End With
Next i
End Sub
取代'_i「'和'_」&i' – Slai
謝謝你,我這樣做,而不再得到「無法獲得樞紐項目屬性.. 。「錯誤,但我確實得到了另一個錯誤:應用程序定義或對象定義的錯誤」。請讓我知道如果你能幫助,任何想法來解決這個問題?謝謝 –