Pivot Charts losing formatting when new data entered

alex1stef2

New Member
Joined
Sep 6, 2017
Messages
2
So I currently have a bunch of hidden sheets with pivot tables on them, and a bunch of unhidden sheets with the corresponding pivot charts. I am querying SQL for a bunch of data, and then the pivot tables feed off this new data to create the charts. My current problem is that every time I run my code the formatting of the pivot charts is reset.


I have tried: `Application.SetDefaultChart FormatName:=0` or just manually setting the graph to a line graph to no avail; it always resets back to the clunky looking point based line graph.


What I am currently trying is:


Code:
    Sub ChartUpdate()
    For Each MySheet In ActiveWorkbook.Worksheets
      For Each MyChart In MySheet.ChartObjects
        MyChart.Activate
        
        MyChart.ChartType = xlLine
      
      Next MyChart
    Next MySheet
    
    ActiveSheet.Activate
    Application.EnableEvents = True

But this doesn't seem to recognise pivot charts as chart objects, as it loops through all the sheets without entering the second `For Each` statement.


Ideally I would prefer not to have to resort to fully reformatting the chart each time as I may have to fix axes etc, which is why the setting default would have been perfect. Otherwise, if this is not possible, any solution to get my second attempt to work would be really helpful!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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