Excel 2007 VBA - Plot Area size not working

  I have a worksheet with multiple types of charts (bar, line, pie). I have created VBA code that adjusts the size of the plot area when the back end data is refreshed. This is necessary because for some reason the charts plot area size will not stay after the data is refreshed, or after the workbook is closed, and re-opened. My code for the bar, and line charts works fine. The pie charts do not want to work with my code though.

Oddly enough, if I change the chart size manually in the worksheet, then run my code, the size stays, but running the code beforehand does nothing. Here is an example of my code:

The code seems to work fine in 2003. Right now I am using 2007 in compatibility mode, this is where I am having the problem.

Any help is greatly appreciated!
'pie charts
For a = 17 To 20
ActiveSheet.ChartObjects("Chart" & a).Activate
With ActiveChart
.PlotArea.Height = 208
.PlotArea.Top = 62
.PlotArea.Width = 208
.PlotArea.Left = 121
end with

Open in new window

Who is Participating?
jm302Connect With a Mentor Author Commented:
   Thanks for the suggestion, but the charts in question are all named Chart17 to 20. I actually came up with a result. It seems like it was just the loop itself that was causing the problem. I ended up just writing out the code for each individual chart and that fixed the problem. I guess the loops were just too fast for the charts.

What is the Pie Chart Number?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.