0
我想用vba從數據表中創建一個數據透視表,標題爲DATA。組織在許多列中,其中三個被接受地稱爲NOM,NOM_MOVE和COMMENT。VBA和數據透視表:獲取兩個數據字段
我想數據透視表有以下字段:山口標籤字段= SUM(值),行標籤字段=評論,值域= NOM的總和的NOM_MOVE
不過總而言之,我的代碼。寫不直到在那裏我有麻煩分配權領域工作或給予正確的字段(即使在使用pivottablewizard和緩存/ createpivottable不同形式
我的代碼了是:
Sub CreatePivot()
' Create the 5 summary pivot tables using the TRADE_LIST sheet as data
Dim pivot1 As Worksheet
Dim datasheet As Worksheet
Dim dataCache As PivotCache
Dim PVT As PivotTable
Dim LastRow As Long
Dim LastCol As Long
Dim dataSource As Range
Dim PVTdest As Range
Set datasheet = Sheets("DATA")
Set pivot1 = Sheets("PIVOT")
' (1) Source data from the TRADE_LIST sheet and create a pivot cache from source data to use for each pivot table
LastRow = datasheet.Cells(1, 1).End(xlDown).Row
LastCol = datasheet.Cells(1, 1).End(xlToRight).Column
Set dataSource = datasheet.Cells(1, 1).Resize(LastRow, LastCol)
Set dataCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=dataSource)
' (2) Create a pivot table
Set PVTdest = pivot1.Cells(2, 2)
Set PVT = dataCache.CreatePivotTable(tabledestination:=PVTdest, tablename:="Comment_Sums")
.. 。
任何幫助非常讚賞