I am able to place multiple charts on a chart sheet by creating an empty chart sheet and then setting the Location of the charts to that empty chart sheet.
'This creates multiple charts within a single chart sheet!
Charts.Add 'Creates empty chart page when empty cell is selected
'Keep track of chart page for later reference
Dim chartSheet As String
chartSheet = ActiveChart.Name
.... 'Create three separate charts with data here
'Now place these charts within our empty chart page
Set chart1 = chart1.Location(Where:=xlLocationAsObject, Name:=chartSheet)
Set chart2 = chart2.Location(Where:=xlLocationAsObject, Name:=chartSheet)
Set chart3 = chart3.Location(Where:=xlLocationAsObject, Name:=chartSheet)
All of the code works up until this point. The chart sheet contains all 3 charts, although the charts are all overlapping. When I try to adjust the position of the charts…
'This code fails to run!
chart1.Parent.Top = 0
chart1.Parent.Left = 0
The code returns a runtime error of Object doesn’t support this property or method. I know it’s possible to move the graphs manually by clicking and dragging, and I know that the above code works if the chart is within a normal worksheet. But for some reason, this code fails when the charts are within a chartsheet. Is there any way to get VBA to do what I want?
Thanks for the help.
After a bit of Experimentation I belive your code isn’t running because
chart1is it’s own worksheet.When I drilled into a selected chart i’ve noticed the following difference. If the chart is embedded (Object in another sheet) the
Parentis aObject/ChartObjectwhich has propertiesTopandLeft(it’s relative location in the worksheet). If the chart is it’s own worksheet, theParentis actually anObject/Thisworkbook' which does not haveToporLeft’ properties. This makes sense because when you create a chartSheet the chart fills the entire sheet area and thus cannot have a relative postion.If you insert a breakpoint on
chart1.Parent.Top = 0and view locals…. you can see what I have explained above.EDIT: to suggest something reagrding your ask in the comments.
The Children are contained in the ‘Shapes’ Collection of the worksheet object. i used the following to show the names of all shapes in a worksheet
From there you should be able to move and format etc.