Create PivotChart from PivotTable

mattty

New Member
Joined
Nov 22, 2007
Messages
14
How can I create a PivotChart using VBA? I ran the macro recorder, and it referred to the source data in the standard way:
ActiveChart.SetSourceData Source:=Range("'sheet1'!$A$3:$C$25")

How do I create a chart that is specifically a PivotChart, referring to a PivotTable as a source, so that when the PT updates, so does the PC?

Seems like it should be a simple solution, but I have had no luck with this.
Thanks in advance!

PS I am using Excel 2007, but I don't think that should matter
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
bump.

sorry, can anyone help with this? I can think of a bunch of workarounds, but I'm sure that there must be some simple, more elegant, solution.

thanks.
 
Upvote 0
When you created the PT you could have created as PT Chart -- doing so would generate both PT & PT Chart simultaneously (I think) -- untested... try recreating.

I'll test myself in a bit...

EDIT: yes, creating as Pivot Chart in first instance will generate the PT -- thus the two are tied... altering one alters the other... so you should find your problem disappears.
 
Last edited:
Upvote 0
Yes, this method works, but it still refers to a PivotTable by its range, rather than by its name. Also, you need to be inserting PTs to begin with (mine already exist).

The solution I used - for the benefit of anyone reading this later on - was to create blank charts, then use code to fill them from the PTs.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,817
Members
449,049
Latest member
cybersurfer5000

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