I just recorded a macro for creating a "Line - Column on 2 axes" chart. But
when I run it, it gives me the following error "Method 'Axes' of objects
'Charts' failed".
I tried modified the code by defining ch1 as chartobject and then doing
this:
set ch1 = activesheet.chartobjects(activesheet.chartobjects.count) and
replacing
with activechart by ch1.chart . It gives me the error " Unable to access
property 'chartobjects' of object worksheet'
Can anybody please help me?
Sub Macro9()
Charts.Add
ActiveChart.ApplyCustomType ChartType:=xlBuiltIn, TypeName:= _
"Line - Column on 2 Axes"
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range("A5:D12"), PlotBy _
:=xlColumns
ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet1"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "performance"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "date"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "xxx"
.Axes(xlCategory, xlSecondary).HasTitle = False
.Axes(xlValue, xlSecondary).HasTitle = True
.Axes(xlValue, xlSecondary).AxisTitle.Characters.Text = "yyy"
End With
ActiveChart.SeriesCollection(2).Select
ActiveChart.SeriesCollection(2).ChartType = xlLineMarkers
ActiveChart.SeriesCollection(2).Select
ActiveChart.SeriesCollection(2).AxisGroup = 2
ActiveChart.ChartArea.Select
End Sub