I'm trying to use vba to create a pivot table from a data from a sheet entitled DATA. Is organised in a number of columns, three of which are called NOM, NOM_MOVE and COMMENT receptively.
I want the pivot table to have the following field: Col labels field = Sum(Values), Row labels field = COMMENT, Values field = sum of NOM, sum of NOM_MOVE
However, the code I have written doesn't work or give the right fields (even in different forms using pivottablewizard and cache/createpivottable.
My code up until where I am having trouble assigning the right fields is:
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")
...
Any help much appreciated