Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default Help with a macro creating a formula for a pivot table

Dear experts,
I have a problem with a code to insert a formula in a Pivot Table.
The name of the items in the formula is not fixed, it depends on which
workbook I choose to run the macro, so I entered a public variable to
indicate this.
Here is the code:

ActiveSheet.PivotTables("PivotTable1").AddDataFiel d
ActiveSheet.PivotTables( _
"PivotTable1").PivotFields(" Volume (MT)" & " " & Data_TimeFrame), _
"Sum of Volume (MT)" & " " & Data_TimeFrame, xlSum

Range("B7").Select
ActiveSheet.PivotTables("PivotTable1").CalculatedF ields.Add "Weighted
Average PM Deviation (by Volume)", _
"='Deviation * Volume' /'"Volume (MT)" & " " & Data_TimeFrame'", True
ActiveSheet.PivotTables("PivotTable1").PivotFields ("Weighted Average PM
Deviation (by Volume)").Orientation = _
xlDataField

The second part of the code does not work!!!!! I get a syntax error.
The code " Volume (MT)" & " " & Data_TimeFrame (where Data_TiemFrame is my
public variable works well to define the Pivot Field, but not the formula!

Coudl you please help me?
Many thanks in advance,
best regards,
--
Valeria
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Help with a macro creating a formula for a pivot table

This is a guess. I think your string (constants & variable) doesn't quite match
what you really have in the data.

Maybe you could record a macro just to see how it shows up.

Then put this line in right before your offending line:

debug.print "****" & " Volume (MT)" & " " & Data_TimeFrame & "****"

(**** just to help see the beginning and end of the string)

Then compare that with what you got when you recorded the macro.




Valeria wrote:

Dear experts,
I have a problem with a code to insert a formula in a Pivot Table.
The name of the items in the formula is not fixed, it depends on which
workbook I choose to run the macro, so I entered a public variable to
indicate this.
Here is the code:

ActiveSheet.PivotTables("PivotTable1").AddDataFiel d
ActiveSheet.PivotTables( _
"PivotTable1").PivotFields(" Volume (MT)" & " " & Data_TimeFrame), _
"Sum of Volume (MT)" & " " & Data_TimeFrame, xlSum

Range("B7").Select
ActiveSheet.PivotTables("PivotTable1").CalculatedF ields.Add "Weighted
Average PM Deviation (by Volume)", _
"='Deviation * Volume' /'"Volume (MT)" & " " & Data_TimeFrame'", True
ActiveSheet.PivotTables("PivotTable1").PivotFields ("Weighted Average PM
Deviation (by Volume)").Orientation = _
xlDataField

The second part of the code does not work!!!!! I get a syntax error.
The code " Volume (MT)" & " " & Data_TimeFrame (where Data_TiemFrame is my
public variable works well to define the Pivot Field, but not the formula!

Coudl you please help me?
Many thanks in advance,
best regards,
--
Valeria


--

Dave Peterson
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 can I detail Pivot Table data without creating a table (Excel2007) Skeletiko[_2_] Excel Discussion (Misc queries) 1 May 5th 10 08:22 AM
How can I detail Pivot Table data without creating a table (Excel2007) Skeletiko Excel Discussion (Misc queries) 0 May 5th 10 12:21 AM
creating a report from a table, pivot table not suitable UKMAN Excel Worksheet Functions 1 April 16th 10 08:35 AM
PIVOT TABLE with a MACRO for FILLing a column with a formula RJ Excel Discussion (Misc queries) 1 August 30th 07 05:32 AM
Creating a pivot table from different sets of data using a macro Éidhne in Ireland Excel Programming 1 November 21st 03 05:20 PM


All times are GMT +1. The time now is 12:41 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"