I am new to working with charts so most of this code was discovered using macros and may be very inefficient.
ChartName = "MyChart1"
RangeName = "MonthR"
Scalex = 0.7
ImageNo = "ImageNo1"
Sub GMCharts(ChartName, RangeName, Scalex, ImageNo)
With Sheets("GROSSMARGIN")
ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select
ActiveChart.SetSourceData Source:=.Range(RangeName)
ActiveChart.Parent.Name = ChartName
ActiveChart.ChartType = xlColumnClustered
ActiveChart.FullSeriesCollection(1).ChartType = xlColumnClustered
ActiveChart.FullSeriesCollection(1).AxisGroup = 1
n = ActiveChart.FullSeriesCollection.Item(1).Name
ActiveChart.FullSeriesCollection(2).ChartType = xlColumnClustered
ActiveChart.FullSeriesCollection(2).AxisGroup = 1
ActiveChart.FullSeriesCollection(3).ChartType = xlLine
ActiveChart.FullSeriesCollection(3).AxisGroup = 1
ActiveChart.FullSeriesCollection(3).ChartType = xlColumnClustered
ActiveChart.FullSeriesCollection(3).AxisGroup = 2
ActiveSheet.ChartObjects(ChartName).Activate
ActiveChart.HasLegend = True
ActiveChart.SetElement (msoElementLegendBottom)
ActiveChart.Legend.LegendEntries(2).Delete
If ChartName = "MyChart1" Then
ActiveChart.ChartTitle.Text = "GrossMargin " & Sheets("GrossMargin").Range("G5").Value ………………………... 'Line with fault
ElseIf ChartName = "MyChart2" Then
ActiveChart.ChartTitle.Text = "GrossMargin " & Sheets("GrossMargin").Range("L5").Value
End If
My problem is that at the line marked as having a fault I get the message "This object has no title"
I may have confused ChartName and ChartTitle but I am lost and need some help please
Bookmarks