我期待創建散點圖是,按下按鈕,在
Excel的VBA:添加散點圖到工作表對象Sheet 1
創建散點圖和使用
A2:A11
作爲
x
值和
B2:B11
爲
y
值。
在底部使用代碼允許我創建一個基於
A1:B3
(從
here得到這個值)的散點圖。它接近,但不完全是我要找的。我如何調整這個以適應我的需求?
基於我想要的值,我現在已經設置好了圖表,所以根據我想要的值創建了圖表,但我無法在Sheet 1
中看到它作爲對象出現。我該怎麼做呢? .Location xlLocationAsObject
似乎不起作用。
Private Sub chartButton_Click()
ActiveWorkbook.Charts.Add
With ActiveWorkbook.ActiveChart
'Data?
.ChartType = xlXYScatter
.SeriesCollection.NewSeries
.SeriesCollection(1).Name = "=""Scatter Chart"""
.SeriesCollection(1).XValues = "=Sheet1!$A$2:$A$11"
.SeriesCollection(1).Values = "=Sheet1!$B$2:$B$11"
'Location
'DON'T KNOW WHAT TO PUT HERE
'.location xlLocationAsObject doesn't work!
'Titles
.HasTitle = True
.ChartTitle.Characters.Text = "Scatter Chart"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text = "X values"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Y values"
.Axes(xlCategory).HasMajorGridlines = True
'Formatting
.Axes(xlCategory).HasMinorGridlines = False
.Axes(xlValue).HasMajorGridlines = True
.Axes(xlValue).HasMinorGridlines = False
.HasLegend = False
End With
End Sub