Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Dynamically changing a calculated field in Pivot Table

Hi - I want to be able to change the formula in a
calculated field of a pivot table when the user updates
the table by choosing an item from a page field.

I know very, very little VBA, but can see by recording a
macro how the formula is changed. What I need help with
is how to do this dynamically when the user changes the
pivot table.

Any help would be appreciated !

thx,

Rick
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 599
Default Dynamically changing a calculated field in Pivot Table

Rick

You can use the Worksheet_Calculate event. This will fire when the pivot
table page is changed (in fact, any time the worksheet is calculated). In
it, you can check the value of the page field and change the formula if
needed.

To code in that event, right click on the sheet tab and choose View Code.
Select Worksheet and Calculate from the drop down boxes at the top of the
pane to insert the Sub and End Sub statements, then code away.

I don't work with pivot tables very much, but if you have some questions
about how to get the page value or change the formula, post back with some
details.

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"Rick" wrote in message
...
Hi - I want to be able to change the formula in a
calculated field of a pivot table when the user updates
the table by choosing an item from a page field.

I know very, very little VBA, but can see by recording a
macro how the formula is changed. What I need help with
is how to do this dynamically when the user changes the
pivot table.

Any help would be appreciated !

thx,

Rick



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Dynamically changing a calculated field in Pivot Table

Thamks for the info !

It works, but creates a new issue for me. It seems that when I change the calculated field, it fires the worksheet_calculate event and it kind of goes through an endless loop. Worksheet calculate event fires - my formula changes which again triggers the calculate event . My code is below, basically the field I am trying to "capture" is when the month is chosen in the page field. I will be expanding that select/case statement for other months once I get past this issue. Thanks for your help !

Rick

Private Sub Worksheet_Calculate()

Select Case activesheet.PivotTables("PivotTable2").PivotFields ("Month").CurrentPage

Case "Sep-03"
activesheet.PivotTables("PivotTable2").CalculatedF ields("Daily Avg").Formula = _
"='Count Task'/21"

Case Else
activesheet.PivotTables("PivotTable2").CalculatedF ields("Daily Avg").Formula = _
"='Count Task'/1"

End Select

End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 599
Default Dynamically changing a calculated field in Pivot Table

Rick

Put this as the first line of your sub

Application.EnableEvents = False

and this at the end of your sub

Me.Calculate
Application.EnableEvents = True

That will prevent the event from being called over and over.

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"Rick" wrote in message
...
Thamks for the info !

It works, but creates a new issue for me. It seems that when I change the

calculated field, it fires the worksheet_calculate event and it kind of goes
through an endless loop. Worksheet calculate event fires - my formula
changes which again triggers the calculate event . My code is below,
basically the field I am trying to "capture" is when the month is chosen in
the page field. I will be expanding that select/case statement for other
months once I get past this issue. Thanks for your help !

Rick

Private Sub Worksheet_Calculate()

Select Case

activesheet.PivotTables("PivotTable2").PivotFields ("Month").CurrentPage

Case "Sep-03"
activesheet.PivotTables("PivotTable2").CalculatedF ields("Daily

Avg").Formula = _
"='Count Task'/21"

Case Else
activesheet.PivotTables("PivotTable2").CalculatedF ields("Daily

Avg").Formula = _
"='Count Task'/1"

End Select

End Sub



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 52
Default Dynamically changing a calculated field in Pivot Table

Dick ,

Thank you so much - I GREATLY appreciate your help !

That tip worked perfectly !

Rick


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
How do I remove a Calculated Field from the Pivot Table field list TheTraveler Excel Discussion (Misc queries) 2 April 9th 10 06:55 PM
Pivot table, IF function, calculated item versus calculated field NomadPurple Excel Discussion (Misc queries) 1 March 9th 10 03:17 PM
Creating a Calculated Field in a Pivot Table for same field dza7 Excel Discussion (Misc queries) 3 October 21st 09 11:22 PM
Calculated Field and Calculated Item in Pivot Table Fred Smith Excel Discussion (Misc queries) 0 March 4th 07 08:15 PM
pivot table formulas for calculated field or calculated item Vicky Excel Discussion (Misc queries) 3 June 6th 06 05:06 AM


All times are GMT +1. The time now is 07:11 AM.

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

About Us

"It's about Microsoft Excel"