I have the following code where I am attempting to change the .Placement property of a chart entitled "MyChart".
The highlighted line results in an error stating "The item with the specified name was not found."
As you can see from the picture, I also tried:
MyChart.Placement = xlFreeFloating
However, it is my understanding that .Placement is a property of a ChartObject and not a Chart itself.
Here is the code from the pic above:
'Format Main Title
MyChart.ChartTitle.Font.Size = 14
MyChart.ChartTitle.Font.Bold = True
MyChart.ChartTitle.Font.Name = "TimesNewRoman"
'Set FreeFloating Property
ActiveSheet.ChartObjects("MyChart").Placement = xlFreeFloating
'MyChart.Placement = xlFreeFloating
How can I change the .Placement property for MyChart (that is, How can I change the .Placement property for a particular chart by name)? Any assistance is appreciated.
===========================================================================
In response to the solution offered: When I try this code, I get this error message:
I don't understand how the name of the graph could be anything but "MyChart". Here is the code that creates this graph:
Set MyChart = ActiveSheet.ChartObjects.Add(Left:=Cells(Row0 + (j3 - 1) * 22, Col0 + ChartStart + 1 + (k3 - 1) * 7).Left, _
Top:=Cells(Row0 + (j3 - 1) * 22, Col0 + ChartStart + 1 + (k3 - 1) * 7).Top, _
Width:=310, _
Height:=300).Chart
MyChart.ChartType = xlXYScatter
MyChart.HasLegend = False
With MyChart
'XAxis Label
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = XName(i3, 1)
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Font.Bold = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Font.Name = "TimesNewRoman"
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Font.Size = 10
'YAxis Label
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = YName
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Font.Bold = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Font.Name = "TimesNewRoman"
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Font.Size = 10
End With
'Remove Gridlines
For Each axs In MyChart.Axes
axs.HasMajorGridlines = False
axs.HasMinorGridlines = False
Next
With MyChart.SeriesCollection.NewSeries
.Name = "Scatterplot of " & YName & " by " & XName(i3, 1)
.Values = y5
.XValues = WorksheetFunction.Index(X4, 0, i3 + 1)
'Format Markers
.MarkerBackgroundColorIndex = 2
.MarkerForegroundColorIndex = 5
.MarkerStyle = 8
End With
'5% around the edges
'XXX 999
'Vertical Axes NOT at zeros
If WorksheetFunction.Min(WorksheetFunction.Index(X4, 0, i3 + 1)) < 0 Then
MyChart.Axes(xlCategory).CrossesAt = MyChart.Axes(xlCategory, xlPrimary).MinimumScale
End If
'Format Main Title
MyChart.ChartTitle.Font.Size = 14
MyChart.ChartTitle.Font.Bold = True
MyChart.ChartTitle.Font.Name = "TimesNewRoman"
'Set FreeFloating Property
ActiveSheet.ChartObjects("MyChart").Placement = Excel.XlPlacement.xlFreeFloating
'MyChart.Placement = xlFreeFloating
'Set FreeFloating Property
' ActiveChart.Select
' Selection.Placement = xlFreeFloating




MyChart.Parent.Placement = xlFreeFloating.