VBA chart error Method 'Axes' of Object '_Chart' failed for secondary axis title
<p>I am trying to add a secondary vertical axis to my chart in VBA. I keep running into this error that says that the Method <code>Axes</code> of the Object <code>_Chart</code> has failed.</p>

<p>I have looked up solutions and implemented a few that stated to make sure that the secondary axis is first active. My code is below. The error occurs in the third to last line when I am trying to state that the secondary axis has a title. Any help is much appreciated since I am still a beginner in VBA.</p>

<pre><code>Public Sub CreateChartForColumnsOneThreeandFive()

    Dim myChartColumnsOneThreeandFive As ChartObject

    Set myChartColumnsOneThreeandFive = ActiveSheet.ChartObjects.Add(Left:=150, Top:=150, Width:=500, Height:=400)

    myChartColumnsOneThreeandFive.Chart.HasTitle = True

    myChartColumnsOneThreeandFive.Chart.ChartTitle.Text = "Phase Detector Readback vs Substrate Forward Power"

    myChartColumnsOneThreeandFive.Chart.Type = xlLine

    myChartColumnsOneThreeandFive.Chart.SetSourceData Source:=ActiveWorkbook.Sheets("Sheet2").Range("C" &amp; processRowBegin &amp; ":C" &amp; processRowEnd)

    myChartColumnsOneThreeandFive.Chart.SetSourceData Source:=ActiveWorkbook.Sheets("Sheet2").Range("E" &amp; processRowBegin &amp; ":E" &amp; processRowEnd)

    myChartColumnsOneThreeandFive.Chart.SeriesCollection(1).Name = Range("C1")

    myChartColumnsOneThreeandFive.Chart.SeriesCollection(1).Name = Range("E1")

    myChartColumnsOneThreeandFive.Chart.SeriesCollection(1).Select

    myChartColumnsOneThreeandFive.Chart.SeriesCollection(1).AxisGroup = 2

    myChartColumnsOneThreeandFive.Chart.HasTitle = True

    myChartColumnsOneThreeandFive.Chart.ChartTitle.Text = "Substrate Forward Power vs Phase Detector Readback"

    myChartColumnsOneThreeandFive.Chart.Axes(xlCategory).HasTitle = True

    myChartColumnsOneThreeandFive.Chart.Axes(xlCategory).AxisTitle.Caption = "Time"

    myChartColumnsOneThreeandFive.Chart.Axes(xlValue, xlPrimary).HasTitle = True

    myChartColumnsOneThreeandFive.Chart.Axes(xlValue, xlPrimary).AxisTitle.Caption = "Substrate Forward Power"

      myChartColumnsOneThreeandFive.Chart.SeriesCollection(1).AxisGroup = xlSecondary

     myChartColumnsOneThreeandFive.Chart.HasAxis(xlValue, xlSecondary) = True

    myChartColumnsOneThreeandFive.Chart.Axes(xlValue, xlSecondary).HasTitle = True

    myChartColumnsOneThreeandFive.Chart.Axes(xlValue, xlSecondary).AxisTitle.Select

    myChartColumnsOneThreeandFive.Chart.Axes(xlValue, xlSecondary).AxisTitle.Text = _
        "Phase Detector Readback"

End Sub
</code></pre>