I am trying to create a macro that will automatically plot data. This is the code I am using so far:
Dim Numsheets As Integer
Dim Datx1l, Daty1 As String
Dim Datx, Daty As String
Numsheets = ActiveWorkbook.Sheets.Count
Datx1 = "DatCol" & Sheets("Graphs").OLEObjects("ComboBox1").Object.ListIndex + 1 & "_" & 1
Daty1 = "DatCol" & Sheets("Graphs").OLEObjects("ComboBox2").Object.ListIndex + 1 & "_" & 1
Charts.Add
ActiveChart.ChartType = xlXYScatterSmooth
ActiveChart.Location Where:=xlLocationAsObject, Name:="Graphs"
With ActiveChart
.SeriesCollection(1).XValues = Datx1
.SeriesCollection(1).Values = Daty1
.SeriesCollection(1).Name = Worksheets(1).Name
For j = 2 To Numsheets - 1
Worksheets(j).Activate
Datx = "DatCol" & Sheets("Graphs").OLEObjects("ComboBox1").Object.ListIndex + 1 & "_" & j
Daty = "DatCol" & Sheets("Graphs").OLEObjects("ComboBox2").Object.ListIndex + 1 & "_" & j
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(j).XValues = Datx
ActiveChart.SeriesCollection(j).Name = Worksheets(j).Name
'ActiveChart.SeriesCollection.NewSeries.Formula = "=SERIES(" & ActiveSheet.Name & ",'" & ActiveWorkbook.Name & "'!Datx,'" & ActiveWorkbook.Name & "'!Daty," & j & ")"
Debug.Print "=SERIES(" & ActiveSheet.Name & ",'" & ActiveWorkbook.Name & "'!Datx,'" & ActiveWorkbook.Name & "'!Daty," & j & ")"
Next
End With
When I run the macro I get an error stating Method 'SeriesCollection' of object'_Chart' failed on the bold line. I have been using other online examples as references and I am not sure why this is not working. Please help!
Dim Numsheets As Integer
Dim Datx1l, Daty1 As String
Dim Datx, Daty As String
Numsheets = ActiveWorkbook.Sheets.Count
Datx1 = "DatCol" & Sheets("Graphs").OLEObjects("ComboBox1").Object.ListIndex + 1 & "_" & 1
Daty1 = "DatCol" & Sheets("Graphs").OLEObjects("ComboBox2").Object.ListIndex + 1 & "_" & 1
Charts.Add
ActiveChart.ChartType = xlXYScatterSmooth
ActiveChart.Location Where:=xlLocationAsObject, Name:="Graphs"
With ActiveChart
.SeriesCollection(1).XValues = Datx1
.SeriesCollection(1).Values = Daty1
.SeriesCollection(1).Name = Worksheets(1).Name
For j = 2 To Numsheets - 1
Worksheets(j).Activate
Datx = "DatCol" & Sheets("Graphs").OLEObjects("ComboBox1").Object.ListIndex + 1 & "_" & j
Daty = "DatCol" & Sheets("Graphs").OLEObjects("ComboBox2").Object.ListIndex + 1 & "_" & j
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(j).XValues = Datx
ActiveChart.SeriesCollection(j).Name = Worksheets(j).Name
'ActiveChart.SeriesCollection.NewSeries.Formula = "=SERIES(" & ActiveSheet.Name & ",'" & ActiveWorkbook.Name & "'!Datx,'" & ActiveWorkbook.Name & "'!Daty," & j & ")"
Debug.Print "=SERIES(" & ActiveSheet.Name & ",'" & ActiveWorkbook.Name & "'!Datx,'" & ActiveWorkbook.Name & "'!Daty," & j & ")"
Next
End With
When I run the macro I get an error stating Method 'SeriesCollection' of object'_Chart' failed on the bold line. I have been using other online examples as references and I am not sure why this is not working. Please help!