如何将系列添加到图表

how to add series to chart

我正在尝试添加新图表 1 sheet 并将 sheet1 中的系列添加到我的图表 1 sheet。

这是我的代码...

Charts.Add
With ActiveChart
    .ChartType = xlLine
    .HasTitle = True
    .ChartTitle.Text = "Closing Price"
    .SeriesCollection.NewSeries
    .FullSeriesCollection.XValues = "=Sheet1!$A:$A1" '<<<<This is the xvalue
    .FullSeriesCollection.Values = "=Sheet1!$B:$B1"  '<<<<This are the value 
End With

请告诉我该怎么做.. 提前致谢

您必须指定系列集合的编号。

Charts.Add
With ActiveChart
    .ChartType = xlLine
    .HasTitle = True
    .ChartTitle.Text = "Closing Price"
    .SeriesCollection.NewSeries
    .FullSeriesCollection(1).XValues = "=Sheet1!$A:$A1" '<<<<This is the xvalue
    .FullSeriesCollection(1).Values = "=Sheet1!$B:$B1"  '<<<<This are the value
End With

顺便说一句,如果你不厌其烦地启动宏记录器,插入一个新图表 sheet,定义新系列,然后停止宏记录器,你会看到所有的命令已满