If I want to add calculated fields to a pivot, I can ask the user to select the column to add the fields after, like this:
Set pivotRange = Application.InputBox("Select the pivot column including the header", "Obtain Range Object", Type:=8)
And then I can add the header of the calculated fields like this:
counter = 0
For Each r In pivotRange.Cells
If counter = 0 Then
r.Offset(, 1).Value = "Profit"
End If
counter = counter + 1
Next
But how do I get the actual pivot fields to calculate, and output the result?
Assuming the field names are "Sum of Cost", "Sum of Revenue"
So I'm looking for the code that would calculate Profit from "Sum of Cost" and "Sum of Revenue" in the pivot table selected by the user.
Bookmarks