Hello, it appears I have a sub which may be running too fast. It works properly when using "Step Into". When running the entire sub I receive an error stating the chart has no title, and the line .ChartTitle.Characters.Text gets highlighted yellow. Please see below. Thanks for the help.
Sub SampleCharts()
Dim i As Integer
For i = 1 To Worksheets.Count Step 2
Worksheets(i).Activate
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatterSmoothNoMarkers
ActiveChart.ChartArea.Select
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).Name = "Sample " & ((i + 1) / 2) & "A"
ActiveChart.SeriesCollection(1).XValues = "='" & Worksheets(i).Name & "'!$B$5:$B$316"
ActiveChart.SeriesCollection(1).Values = "='" & Worksheets(i).Name & "'!$C$5:$C$316"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(2).Name = "Sample " & ((i + 1) / 2) & "B"
ActiveChart.SeriesCollection(2).XValues = "='" & Worksheets(i + 1).Name & "'!$B$5:$B$316"
ActiveChart.SeriesCollection(2).Values = "='" & Worksheets(i + 1).Name & "'!$C$5:$C$316"
'The following code sets every other data set to the same line color
'c = (i Mod 2) * 200
With ActiveChart.SeriesCollection(1).Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(200, 200, 15)
.Transparency = 0
End With
'
With ActiveChart.SeriesCollection(2).Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(200, 0, 15)
.Transparency = 0
End With
'
'Following Code Sets Axis Scales
With ActiveChart.Axes(xlValue, xlPrimary)
.HasTitle = True
.AxisTitle.Characters.Text = "Torque (in-oz)"
.MaximumScale = 14
.MinimumScale = 0
.MajorUnit = 2
End With
With ActiveChart.Axes(xlCategory, xlPrimary)
.HasTitle = True
.AxisTitle.Characters.Text = "Angle (Degrees)"
.MaximumScale = 370
.MinimumScale = 0
.MajorUnit = 60
End With
ActiveChart.HasLegend = False
'
Dim cTitle As String
Dim eTitle As String
eTitle = CStr((i + 1) / 2)
cTitle = "Sample "
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = cTitle & eTitle
End With
Next i
End Sub
Bookmarks