- 帖子
- 1
- 主題
- 1
- 精華
- 0
- 積分
- 2
- 點名
- 0
- 作業系統
- Vista
- 軟體版本
- Office2007
- 閱讀權限
- 10
- 性別
- 女
- 註冊時間
- 2011-12-23
- 最後登錄
- 2011-12-23
|
VBA產生樞紐分析表RowField小計問題
本帖最後由 ahager 於 2011-12-23 22:15 編輯
各位高手你好~
有需要用到VBA產生樞紐分析表
目前練習問題如下

有需要用到Department 和 Category的RowField
但是Department不需要產生小計
在excel裡的操作已經找出來了
在列標籤--> Department --> 欄位設定 --> 小計與篩選--> 從自動改為無就好了
但這段語法不太會寫
請知道的高手解答 感謝 ^_____^
以下是我參考的網頁和程式碼
http://blog.xuite.net/crdotlin/excel/7649722- With PT
- ' 設定欄位
- .PivotFields("DEPARTMENT").Orientation = xlRowField
- .PivotFields("Category").Orientation = xlRowField
- .PivotFields("MONTH").Orientation = xlColumnField
- .PivotFields("DIVISION").Orientation = xlPageField
- .PivotFields("BUDGET").Orientation = xlDataField
- .PivotFields("ACTUAL").Orientation = xlDataField
-
- ' 新增計算欄位Variance, 其值為BUDGET減ACTUAL欄位
- .CalculatedFields.Add "Variance", "=BUDGET-ACTUAL"
- ' 將Variance欄位置於資料範圍
- .PivotFields("Variance").Orientation = xlDataField
-
- ' 在MONTH欄上新增計算資料項目Q1,Q2,Q3,Q4等, 其值分別為各計的月份和
- With .PivotFields("MONTH")
- With .CalculatedItems
- .Add "Q1", "= Jan+ Feb+ Mar"
- .Add "Q2", "= Apr+ May+ Jun"
- .Add "Q3", "= Jul+ Aug+ Sep"
- .Add "Q4", "= Oct+ Nov+ Dec"
- End With
-
- ' 設定Q1,Q2,Q3,Q4計算項目的位置
- .PivotItems("Q1").Position = 4
- .PivotItems("Q2").Position = 8
- .PivotItems("Q3").Position = 12
- .PivotItems("Q4").Position = 16
- End With
複製代碼 |
|