Hello, I am trying to plot 4 curves in the same chart; two on primary axis and two on secondary axis using VBA. The plots are done okay. But when I try to write the secondary axis title it gives Runtime error/automation error. It does not like setting the title (right now those 5 lines are commented) for secondary axis.
Any help/lead would be appreciate.d
With Worksheets("Graph").Shapes.AddChart.Chart
.Parent.Left = Range("B6").Left
.Parent.Top = Range("B6").Top
.Parent.Height = 300
.Parent.Width = 500
.Legend.Position = xlLegendPositionBottom
'remove existing series, if any
While .SeriesCollection.Count > 0
.SeriesCollection(1).Delete
Wend
'set properties for chart
.HasTitle = True
.ChartType = xlLine
.HasLegend = True
.HasAxis(xlValue, xlPrimary) = True
With .Axes(xlValue, xlPrimary)
.HasTitle = True
.AxisTitle.Caption = "Watt"
End With
'.HasAxis(xlValue, xlSecondary) = True
'With .Axes(xlValue, xlSecondary)
'.HasTitle = True
'.AxisTitle.Text = "Secondary Y Axis"
'End With
.ChartTitle.Text = "Demo Plot"
.Axes(xlCategory).CategoryType = xlCategoryScale
.Axes(xlCategory).TickLabels.Orientation = 45 'x-labels in 45deg
.ChartArea.Format.Fill.ForeColor.RGB = RGB(230, 255, 255)
'add each series to chart
Dim j As Long
For j = 2 To 5 Step 1
Debug.Print j
With .SeriesCollection.NewSeries
If j Mod 2 = 0 Then
.AxisGroup = 2
Any help/lead would be appreciate.d
With Worksheets("Graph").Shapes.AddChart.Chart
.Parent.Left = Range("B6").Left
.Parent.Top = Range("B6").Top
.Parent.Height = 300
.Parent.Width = 500
.Legend.Position = xlLegendPositionBottom
'remove existing series, if any
While .SeriesCollection.Count > 0
.SeriesCollection(1).Delete
Wend
'set properties for chart
.HasTitle = True
.ChartType = xlLine
.HasLegend = True
.HasAxis(xlValue, xlPrimary) = True
With .Axes(xlValue, xlPrimary)
.HasTitle = True
.AxisTitle.Caption = "Watt"
End With
'.HasAxis(xlValue, xlSecondary) = True
'With .Axes(xlValue, xlSecondary)
'.HasTitle = True
'.AxisTitle.Text = "Secondary Y Axis"
'End With
.ChartTitle.Text = "Demo Plot"
.Axes(xlCategory).CategoryType = xlCategoryScale
.Axes(xlCategory).TickLabels.Orientation = 45 'x-labels in 45deg
.ChartArea.Format.Fill.ForeColor.RGB = RGB(230, 255, 255)
'add each series to chart
Dim j As Long
For j = 2 To 5 Step 1
Debug.Print j
With .SeriesCollection.NewSeries
If j Mod 2 = 0 Then
.AxisGroup = 2