PDA

View Full Version : Change the position and size of the Pie Chart



lcpx
06-21-2006, 09:55 AM
In excel, how can change the position and size of a pie VBA generated chart with VBA code.

Basically I wanted to create 7 charts based on the raw data in the same worksheet. There is no problem on creating the charts by using Charts.Add method in VBA, but once the chart has been created, I couldn?t change the position and the size of them via VBA code because I don?t know the name of those charts and failed to find it from Excel manual.

It seems excel would give a object name automatically when a chart object has been created.
I've been stucked for the whole day and couldn't find a solution. Thanks very much for your time and help.

Ken Puls
06-21-2006, 10:01 AM
Hi there,

My first stop when I'm playing with Charts is Jon Peltier's site. This article (http://www.peltiertech.com/Excel/ChartsHowTo/ResizeAndMoveAChart.html) specifically deals with moving and resizing charts using VBA.

HTH,

lucas
06-21-2006, 10:12 AM
This might get you started....from a post by Jake-seems they are numbered according to the order on the sheet. Someone correct me if I'm wrong.


Sub x()
ActiveSheet.ChartObjects(2).Cut
Sheets("Sheet2").Select
Range("B5").Select
ActiveSheet.Paste
End Sub

will move the second chart to sheet 2 range B5

Ken Puls
06-21-2006, 10:42 AM
This might get you started....from a post by Jake-seems they are numbered according to the order on the sheet. Someone correct me if I'm wrong.

Interesting... I would have thought they would be numbered according to the order they were created, although I have no empirical evidence to support this. It just would make sense, or inserting a new chart above an existing one would break all the VBA code done...

I guess either is possible...