[算表] VBA產生樞紐分析表,"值"的位置

看板Office作者 (SKY)時間7年前 (2019/02/25 18:53), 7年前編輯推噓0(002)
留言2則, 1人參與, 7年前最新討論串1/1
軟體: Office 365 Excel 正在嘗試使用VBA進行樞紐分析,有成功的產生樞紐分析表, 但是有一個自動產生的項目:"值" 現在是在"列"的項目下面,我希望把它移動到 "欄"的項目下面,但是目前嘗試了一些語法都沒有成功。 樞紐分析中的畫面截圖:https://imgur.com/YcIZYe0
附上目前使用的語法: Dim PTCache As PivotCache Dim PT As PivotTable Set PTCache = ThisWorkbook.PivotCaches.Add _ (SourceType:=xlDatabase, _ SourceData:=ActiveSheet.Range(Cells(1, 1), Cells(workingRow, workingColumn))) Set PT = PTCache.CreatePivotTable _ (TableDestination:="", _ TableName:="PivotTable2") With PT .PivotFields("AAA").Orientation = xlDataField .PivotFields("BBB").Orientation = xlDataField .PivotFields("CCC").Orientation = xlRowField .PivotFields("DDD").Orientation = xlRowField '網路上查到可能可以用下面這行來移動"值",但如果加了下面這行就會錯誤 '.PivotFields("值").Orientation = xlColumnField End With -- 我查到有人說可以移動的方式是在英文版當中使用 .PivotFields("value").Orientation = xlColumnField 我是用中文版的Excel,所以我嘗試了用"value"跟"值",但是目前都沒有成功。 請問有什麼其他可行的方式嗎? 謝謝! -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.169.254.239 ※ 文章網址: https://www.ptt.cc/bbs/Office/M.1551092029.A.807.html ※ 編輯: homelife (1.169.254.239), 02/25/2019 19:05:51

02/25 19:30, 7年前 , 1F
要加的那行改以
02/25 19:30, 1F

02/25 19:30, 7年前 , 2F
.datapivotfield.orientation= xlcolumnfield
02/25 19:30, 2F
您好,照著您的方式成功了! 謝謝! ※ 編輯: homelife (1.169.254.239), 02/25/2019 19:38:37
文章代碼(AID): #1SSyazW7 (Office)
文章代碼(AID): #1SSyazW7 (Office)