• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1607
  • Last Modified:

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

1 Solution
What is the Pie Chart Number?
jm302Author 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.


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now