sweeneytime
Board Regular
- Joined
- Aug 23, 2010
- Messages
- 183
Hi,
I am automating a pivot table and I want more than 1 data fields. For the row fields it accepts an array:
But it won't accept that for the data fields, below is the code for a single field
I have looked at this problem a few time with no solution. Would anyone know the answer or point me in the right direction?
I even have a pivot table book, but it some how doesn't cover this exact question
Cheers,
Sweeneytime
Full Code I'm using
I am automating a pivot table and I want more than 1 data fields. For the row fields it accepts an array:
HTML:
pt.AddFields RowFields:=Array("GPProject", "Department",)
But it won't accept that for the data fields, below is the code for a single field
HTML:
pt.AddDataField pt.PivotFields("FY13/14"), "Sum of Amount"
I have looked at this problem a few time with no solution. Would anyone know the answer or point me in the right direction?
I even have a pivot table book, but it some how doesn't cover this exact question

Cheers,
Sweeneytime
Full Code I'm using
HTML:
Sub ForecastPVBoard()
Dim LR As Long
Dim wb As Workbook
Dim pt As PivotTable
Dim pc As PivotCache
Dim Data As Range
'Find last row
LR = Range("AD" & Rows.Count).End(xlUp).Row
Sheets("Forecast Data").Select
With Sheets("Forecast Data")
'Data for pivot table
Range("A1").Select
Range(ActiveCell.Offset(0, 10), Selection.End(xlDown)).Select
Set Data = Selection
Range("A1").Select
Data.Select
Set wb = ActiveWorkbook
Set pc = wb.PivotCaches.Add(SourceType:=xlDatabase, _
SourceData:=Data)
'Create PV
Sheets("PV Report Board").Select
Set pt = pc.CreatePivotTable _
(Tabledestination:=wb.Worksheets("PV Report Board").Range("A1"), _
TableName:="Data")
'Add rows and column fields
pt.AddFields RowFields:=Array("GPProject", "Department", "Organization_Name", "Person_Name", "Position", "Grade_Name", "GRade_Step", "Assignment_End_Date", "Time_Fraction")
'Add Value Fields
pt.AddDataField pt.PivotFields("FY13/14"), "Sum of Amount"
Call NoSubtotals
'PasteSpecial PV
pt.TableRange2.Copy
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
End With
Application.ScreenUpdating = True
Application.Calculation = xlAutomatic
End Sub