URGENT! Need to remove only 1 calculated field

sourabh_ajmera

New Member
Joined
Jul 17, 2014
Messages
36
Hello Everybody,

I am stuck at a problem that I been trying to solve for almost a day now. My problem is to remove a specific calculated field from the pivot table.
I know we cannot hide the field and I do not want it gone forever as I need it somewhere else so I was surfing through different sites and I stumbled upon this code. This code deletes all the calculated field which I do not want it to do.
Code:
Sub test()


Sub RemoveCalculatedFields()
Dim pt As PivotTable
Dim pf As PivotField
Dim pfNew As PivotField
Dim strSource As String
Dim strFormula As String
Set pt = ActiveSheet.PivotTables("TDPivotTable")
For Each pf In pt.CalculatedFields
    strSource = pf.SourceName
    strFormula = pf.Formula
    pf.Delete
    Set pfNew = pt.CalculatedFields.Add(strSource, strFormula)
Next pf


End Sub

My pivot tables contain 3 calculated fields and I want to hide/remove one field only (name of the field in pivot table : "Excess")
Can you please help me out to figure a way to hide this one specific calculated field

I am using Excel 2010
Thanks a ton in advance!
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Like this:
Code:
With pt.DataFields("Sum of Excess")
.Parent.PivotItems(.Name).Visible = False
End With
for example.
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,458
Members
449,085
Latest member
ExcelError

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top