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")
.. 。
任何帮助非常赞赏