Hi
I have managed to add Calculated fields to the pivot table as shown in the code below but I am not able to get these calculated fields to appear in the values list using vba. Can anybody please enlighten me on how I can add the calculated fields to the values list using vba
Portion of the code below: (pvtTable is a passed in pivot table into the method)
...
I have managed to add Calculated fields to the pivot table as shown in the code below but I am not able to get these calculated fields to appear in the values list using vba. Can anybody please enlighten me on how I can add the calculated fields to the values list using vba
Portion of the code below: (pvtTable is a passed in pivot table into the method)
...
Code:
Dim pc As PivotCache
Set pc = wb.PivotCaches.Add(xlExternal)
Dim pt As PivotTable
pc.Connection = pvtTable.PivotCache.Connection
pc.MaintainConnection = False
Dim oldPivotDetails(1 To 24, 1 To 24) As String
Dim count As Integer
For count = LBound(oldPivotDetails) To UBound(oldPivotDetails)
oldPivotDetails(count, 1) = pvtTable.CalculatedFields.Item(count).Name
oldPivotDetails(count, 2) = pvtTable.CalculatedFields.Item(count).formula
Next
Set pt = pc.CreatePivotTable("", , False)
pvtTable.CacheIndex = pc.index
pvtTable.ManualUpdate = True
For count = LBound(oldPivotDetails) To UBound(oldPivotDetails)
pvtTable.CalculatedFields.Add Name:=oldPivotDetails(count, 1), formula:=oldPivotDetails(count, 2)
Next
pvtTable.ManualUpdate = False
pvtTable.SaveData = False
pt.TableRange1.Worksheet.Delete
Last edited by a moderator: