Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
nc nc is offline
external usenet poster
 
Posts: 119
Default Pivot table calculated field

I have two macros below, to one to create and the other to delete calculated
field.

When I run create, the macro completes successfully. When I run the latter
I get an error message "Method 'Delete' of object 'PivotField' failed. Can
you please help me amend the 'DeleteCalcFields_Click() macro.



Private Sub DeleteCalcFields_Click()

For Each fld In _
Worksheets("Create calc
fields").PivotTables("PivotTable1").CalculatedFiel ds
fld.Delete
Next

End Sub

Private Sub CreateCalcFields_Click()

Dim rngItems As Range
Dim ws As Worksheet
Dim pt As PivotTable
Dim c As Range
Dim pf As PivotField


Set ws = Worksheets("Create calc fields")
Set pt = ws.PivotTables("PivotTable1")
Set rngItems = ws.Range("AddItems")

For Each c In rngItems
On Error Resume Next
Set pf = ws.PivotTables("PivotTable1").CalculatedFields(c.V alue)
On Error GoTo 0
If Not pf Is Nothing Then
ws.PivotTables("PivotTable1").CalculatedFields(c.V alue) _
.StandardFormula = c.Offset(0, 1).Value
Else
ws.PivotTables("PivotTable1").CalculatedFields.Add _
c.Value, c.Offset(0, 1).Value, True
' pt.PivotFields(c.Value).Orientation = xlDataField
End If
Next c

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,180
Default Pivot table calculated field

Add:
Dim fld As PivotField
  #3   Report Post  
Posted to microsoft.public.excel.misc
nc nc is offline
external usenet poster
 
Posts: 119
Default Pivot table calculated field



"Herbert Seidenberg" wrote:

Add:
Dim fld As PivotField


Herbert. Thanks for your suggestion, but unfortunately it did not solve the
problem.
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,180
Default Pivot table calculated field

Here is my full example:
http://www.mediafire.com/file/jymwmum5nyg/01_02_09.xlsm

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculated Field and Calculated Item in Pivot Table Fred Smith Excel Discussion (Misc queries) 0 March 4th 07 08:15 PM
pivot table calculated field Spencer Hutton Excel Worksheet Functions 1 December 15th 06 08:08 PM
pivot table formulas for calculated field or calculated item Vicky Excel Discussion (Misc queries) 3 June 6th 06 05:06 AM
Calculated field in Pivot Table jerry Excel Discussion (Misc queries) 0 October 25th 05 08:40 PM
Calculated Field in Pivot Table Edgar Thoemmes Excel Worksheet Functions 0 December 23rd 04 11:59 AM


All times are GMT +1. The time now is 03:39 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"