I'm using VBA to graph data in a program I created in Excel 2010. I sent it to another computer, which has Excel 2013 instead, and I found that everything worked perfectly except for this graphing issue.
My code will create the graphs, and size them perfectly, but it won't actually graph any of the data points. In my code, I also add and delete series, and I notice that the number of series is correct on the side, but that the series didn't retain the custom names I gave them.
But here's the twist. When I right click on the chart and click "select data", all of the data immediately pops up, including all of my custom names for the series. I don't even go into select data or anything. The moment I click it, all of the values just pop up immediately.
Here is an imgur album of what it looks like before/after. Note that I do absolutely nothing other than right click and select the option "select data". It's like the data is already selected, but just doesn't show up until I click 'select data".
Why would Excel 2013 be doing this? How do I make these values actually show up via VBA methods? I'll add a sample of the graphing code I use below.
'Setting the range the chart will cover
Set rngChart = ActiveSheet.Range(Cells(Counter + 3, 4), Cells(Counter + 27, 10))
'Dimensioning the chart and choosing chart type
Set co = ActiveSheet.Shapes.AddChart(xlXYScatter, rngChart.Cells(1).Left, rngChart.Cells(1).Top, rngChart.Width, rngChart.Height)
Set cht = co.Chart
Set sc = cht.SeriesCollection
'Remove any default series
Do While sc.Count > 0
sc(1).Delete
Loop
'Setting chart data
'Series 1
With sc.NewSeries
.Name = "=Sheet1!$C$1"
.XValues = "=Sheet2!$A$2:$A$" & SimpleTracker + 1
.Values = "=Sheet2!$B$2:$B$" & SimpleTracker + 1
.MarkerSize = 3
.MarkerStyle = xlMarkerStyleCircle
End With
'Series 2
With sc.NewSeries
.Name = "=Sheet1!$B$1"
.XValues = "=Sheet1!$A$2:$A$" & Counter + 1
.Values = "=Sheet1!$B$2:$B$" & Counter + 1
.MarkerSize = 5
.MarkerStyle = xlMarkerStyleCircle
.MarkerBackgroundColorIndex = 10
.MarkerForegroundColorIndex = 10
End With
'Setting chart labels
With cht
.HasTitle = True
If n = 0 Then
.ChartTitle.Characters.Text = "Simple Fit - CFL Over Time"
ElseIf Range("I" & n) = "Regression Title" Then
.ChartTitle.Characters.Text = Range("J" & n).Text
Else
.ChartTitle.Characters.Text = "Simple Fit - CFL Over Time"
End If
.Axes(xlCategory, xlPrimary).HasTitle = True
If DayTracker = 1 Then
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Time (Days)"
ElseIf HourTracker = 1 Then
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Time (Hours)"
Else
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "Time (Minutes)"
End If
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "CFL"
.Axes(xlCategory).HasMajorGridlines = True
.Axes(xlCategory).HasMinorGridlines = True
End With
I also want to note that this code still works perfectly in Excel 2010, and that the graphing still works there. It just doesn't work in Excel 2013.
Thank you for reading! If you have any questions or need any clarification, just let me know.
Replace
With sc.NewSeries
with
With cht.SeriesCollection.NewSeries
I had the same issue in Excel 2013. I don't know why, but this solution works for me.