Copy a calculated field from a pivot table

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
 
D

Debra Dalgleish

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
'====================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top