2016-08-07 39 views
0

我可以使用VBA在行中爲「Pog Group」和「Item#」編寫代碼。然後,我想在此數據透視表中通過VBA多次計算每個Pog組中的Item#重複次數。我可以總結他們,但我不知道如何計算它們。在下面的圖片中,編碼可以實現左側數據透視表上的效果,但我想在右側實現效果。非常感謝您的幫助!!!您好我想用VBA來計算數據透視表

Sub creatpivottable2() 

Dim PT As PivotTable 
Dim PTCache As PivotCache 
Worksheets("SKU & POG DataResource").Select 

Set PTCache = ActiveWorkbook.PivotCaches.Create(xlDatabase, Cells(1, 1).CurrentRegion) 
Set PT = ActiveSheet.PivotTables.Add(PivotCache:=PTCache, TableDestination:=Range("E4")) 

With PT 
.PivotFields("POG Group").Orientation = xlRowField 
.PivotFields("Item #").Orientation = xlRowField 
.PivotFields("Trait #").Orientation = xlDataField 


End With 


End Sub 

enter image description here

+0

請看我上傳的圖片,顯示我現在認識的影響,我想顯示效果。問題是如何使用數據在Pivotfields –

+2

hmm ..嘗試宏記錄?其良好的參考來源 – Rosetta

回答

0

使用這段代碼:

With PT 
    .PivotFields("POG Group").Orientation = xlRowField 
    .PivotFields("Item #").Orientation = xlRowField 
    With .PivotFields("Trait #") 
     .Orientation = xlDataField 
     .Function = xlCount 
    End With 
End With 
+0

@PatrickGong:你是否通過了它? – user3598756

+0

@PatrickGong:給你嘗試和幫助你的人提供feedbakcs會很高興 – user3598756