Copy a calculated field from a pivot table

  • Thread starter Thread starter slscanlon3
  • Start date Start date
S

slscanlon3

I have 2 pivot tables on 2 different worksheets in a workbook based
off of the same raw data from a 3rd worksheet. I created many
calculated fields in one of the pivot table and I want to use the same
ones in the second. Can I copy the details of those fields into the
second pivot table without having to set them up all over again? They
do not show in the list of calculated fields created.

Thanks,
Sheryl
 
You could programmatically copy the calculated fields from one pivot
table to another, for example:

'====================
Sub CreateCalsFields()
Dim pt As PivotTable
Dim pf As PivotField
Dim pt2 As PivotTable
Dim pf2 As PivotField

Set pt = Sheets("Pivot").PivotTables(1)
Set pt2 = Sheets("Sheet1").PivotTables(1)

For Each pf In pt.CalculatedFields
Set pf2 = pt2.CalculatedFields.Add(Name:=pf.Name, _
Formula:=pf.Formula)
pf2.Orientation = xlDataField
Next pf

End Sub
'====================
 
Back
Top