I am using the following code to generate a graph with 2 series. I then want to convert one series to a second axis. The code seems to work fine in Excel 2007 but the code halts and gives the error message "Select method of series class failed", when it comes to the line: ".select" after "With .SeriesCollection(2)"
With ActiveSheet
' What range should chart cover
Set myChtRange = Range("B30:M50")
' What range contains data for chart
Set myDataRange = Range("A27:M28")
' Cover chart range with chart
Set objChart = .ChartObjects.Add( _
Left:=myChtRange.Left, Top:=myChtRange.Top, _
Width:=myChtRange.Width, Height:=myChtRange.Height)
' Put all the right stuff in the chart
With objChart.Chart
.ChartArea.AutoScaleFont = False
.ChartType = xlColumnClustered
.SetSourceData Source:=myDataRange
.HasTitle = True
.ChartTitle.Characters.Text = "My Title"
.ChartTitle.Font.Bold = True
.ChartTitle.Font.Size = 12
With .Axes(xlCategory, xlPrimary)
.HasTitle = True
With .AxisTitle
.Characters.Text = "Month"
.Font.Size = 9
.Font.Bold = True
End With
End With
With .Axes(xlValue, xlPrimary)
.HasTitle = True
With .AxisTitle
.Characters.Text = "£"
.Font.Size = 9
.Font.Bold = True
End With
End With
With .SeriesCollection(2)
.Select
.AxisGroup = 2
.ChartType = xlLineMarkers
With ActiveChart
.Axes(xlValue, xlSecondary).HasTitle = True
.Axes(xlValue, xlSecondary).AxisTitle.Characters.Text = "GP £"
ActiveChart.HasLegend = True
ActiveChart.Legend.Select
Selection.Position = xlBottom
End With
End With
End With
End With
End Sub
Can anyone assist.
Many thanks in advance.
With ActiveSheet
' What range should chart cover
Set myChtRange = Range("B30:M50")
' What range contains data for chart
Set myDataRange = Range("A27:M28")
' Cover chart range with chart
Set objChart = .ChartObjects.Add( _
Left:=myChtRange.Left, Top:=myChtRange.Top, _
Width:=myChtRange.Width, Height:=myChtRange.Height)
' Put all the right stuff in the chart
With objChart.Chart
.ChartArea.AutoScaleFont = False
.ChartType = xlColumnClustered
.SetSourceData Source:=myDataRange
.HasTitle = True
.ChartTitle.Characters.Text = "My Title"
.ChartTitle.Font.Bold = True
.ChartTitle.Font.Size = 12
With .Axes(xlCategory, xlPrimary)
.HasTitle = True
With .AxisTitle
.Characters.Text = "Month"
.Font.Size = 9
.Font.Bold = True
End With
End With
With .Axes(xlValue, xlPrimary)
.HasTitle = True
With .AxisTitle
.Characters.Text = "£"
.Font.Size = 9
.Font.Bold = True
End With
End With
With .SeriesCollection(2)
.Select
.AxisGroup = 2
.ChartType = xlLineMarkers
With ActiveChart
.Axes(xlValue, xlSecondary).HasTitle = True
.Axes(xlValue, xlSecondary).AxisTitle.Characters.Text = "GP £"
ActiveChart.HasLegend = True
ActiveChart.Legend.Select
Selection.Position = xlBottom
End With
End With
End With
End With
End Sub
Can anyone assist.
Many thanks in advance.