Captions in Pivot Tables (VBA)

JayCheezey

New Member
Joined
Jul 25, 2014
Messages
17
So I'm new to coding and I was just wondering...


Basically, I''ve created a code (for pivot tables) that auto refreshes and inputs the new field into the Values table relative to a cell that has a value (201428).


ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields(Sheets("Pivot").Range("CC1").Value), "Sum of 201428", xlSum

I've managed to get excel to add the field that has the value of CC1 to the Values category. That was the hard part... The easy part I can't figure out is how to display this value in the caption. Above, you see that the value 201428 is displayed. But I want the sum of ... to be relative to a cell.

I tried to do this:

ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields(Sheets("Pivot").Range("CC1").Value), Sheets("Pivot").Range("CC1").Value, xlSum

But it didn't work...

I know there's a simple solution to this. Just don't know what haha...

Thanks for the help in advance!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
The caption and name of a pivot field cannot be the same. Try this to see how it would work:
Code:
ActiveSheet.PivotTables("PivotTable1").AddDataField _
ActiveSheet.PivotTables("PivotTable1").PivotFields(Sheets("Pivot").Range("CC1").Value), _
"Sum of" & Sheets("Pivot").Range("CC1").Value, xlSum
 
Upvote 0
Thanks a lot Gavin! Works perfectly!

The caption and name of a pivot field cannot be the same. Try this to see how it would work:
Code:
ActiveSheet.PivotTables("PivotTable1").AddDataField _
ActiveSheet.PivotTables("PivotTable1").PivotFields(Sheets("Pivot").Range("CC1").Value), _
"Sum of" & Sheets("Pivot").Range("CC1").Value, xlSum
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

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