Hi,
I have written a program that works on my desktop computer, running a macro through all the worksheets and creating a chart on each one containg two series, on from columns A and B and the second from columns A and C, then moving onto the next spreadsheet. However, when I try to run it on my laptop it runs through the first spreadsheet fine but then crashes when it tries to plot the graph in the second one, and I can't work out why. Both computers have Excel 2007, and I have uninstalled and reinstalled the version on the laptop to check, but it still keeps coming up with this problem. I don't know if it's helpful, but I tried to plot the second graph 'manually' and it came up with the error 'Some chart types cannot be combined with different chart types. Select a different chart type'. I've included my code below.
Thanks for any help!
I have written a program that works on my desktop computer, running a macro through all the worksheets and creating a chart on each one containg two series, on from columns A and B and the second from columns A and C, then moving onto the next spreadsheet. However, when I try to run it on my laptop it runs through the first spreadsheet fine but then crashes when it tries to plot the graph in the second one, and I can't work out why. Both computers have Excel 2007, and I have uninstalled and reinstalled the version on the laptop to check, but it still keeps coming up with this problem. I don't know if it's helpful, but I tried to plot the second graph 'manually' and it came up with the error 'Some chart types cannot be combined with different chart types. Select a different chart type'. I've included my code below.
Thanks for any help!
Code:
Dim rngXData As Range
Dim rngYData As Range
Dim rngYData2 As Range
Dim NumRows As Long
'
Set rngXData = Range("A5", Cells(Rows.Count, 1).End(xlUp))
Set rngYData = rngXData.Offset(0, 1)
Set rngYData2 = rngXData.Offset(0, 2)
With ActiveSheet.Shapes.AddChart.Chart
Do While .SeriesCollection.Count > 0
' remove any series added automatically
.SeriesCollection(1).Delete
Loop
With .SeriesCollection.NewSeries
.Values = rngYData
.XValues = rngXData
.Name = "='" & ActiveSheet.Name & "'!" & rngYData.Offset(-1, 0).Cells(1, 1).Address
End With
With .SeriesCollection.NewSeries
.Values = rngYData2
.XValues = rngXData
.Name = "='" & ActiveSheet.Name & "'!" & rngYData.Offset(-2, 0).Cells(2, 2).Address
End With
.ChartType = xlXYScatterSmoothNoMarkers
End With