Here is the code I have written to regenerate a chart each time a button is pressed:
Sub MakeChart()
ActiveWorkbook.Charts("cht_hgn_hgn").Delete
Dim s As Series
Dim sh As Worksheet
Dim cs As Chart
Set sh = Worksheets("clc_hgn_hgn")
Set cs = ActiveWorkbook.Charts.Add
cs.Name = "cht_hgn_hgn"
cs.ChartType = xlLine
For iCount = 3 To 3
Debug.Print (iCount)
Set s = cs.SeriesCollection.NewSeries
s.Name = sh.Cells(1, iCount).Value
s.values = sh.Range(sh.Cells(3, iCount), sh.Cells(41, iCount))
s.XValues = sh.Range(sh.Cells(3, 1), sh.Cells(41, 1))
Next iCount
End Sub
Here is a screenshot of the source data:
https://i.sstatic.net/OrZHi.jpg
Here is a screenshot of the chart:
https://i.sstatic.net/jfFno.jpg
The problem is that the labels (at the very least) in the legend and along the x axis appear to be really messed up. What have I done wrong in my code?
Thanks!!