0
這裏建立時爲圖表是我寫每一個按鈕被按下的時間來重新生成的圖表的代碼:使用VBA
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
這裏是源數據的屏幕截圖:
這裏是圖表的屏幕截圖:
問題在於圖例中的標籤(至少)和沿着x軸看起來確實搞砸了。我在代碼中做了什麼錯誤?
謝謝!
如果可以手動修改圖表,然後錄製宏並檢查生成的代碼。問題在於源範圍中的空單元格。 – Slai