将XValues添加到系列线图中

时间:2018-01-19 08:17:57

标签: excel vba

我在将X值添加到系列线图时遇到问题。

我有这样的代码

Set Xacross = Range(Cells(2, 1), Cells(TimeNumber, 1))

Worksheets("Graph").Activate

    With ActiveChart.SeriesCollection.XValues
        .Name = "Time"
        .Values = Xacross
    End With

但每当我运行代码时,我总是得到Error 438

我也尝试使用像

这样的代码

ActiveChart.SeriesCollection.XValues = Range(Cells(2,1),Cells(TimeNumber,1))

以及

Xacross = Range(Cells(2,1),Cells(TimeNumber,1) 
ActiveChart.SeriesCollection.XValues = Xacross

您能提供任何解决方案或解决方案的位置吗?

谢谢

2 个答案:

答案 0 :(得分:0)

你要么......

- 必须指定您正在编辑的SeriesCollection

SeriesCollection(index).XValues

- 或者必须添加新的seriescollection

SeriesCollection.Add source:=Xacross

关于解决方案的位置:通常尝试在Google中输入有问题的对象(seriescollection),如下所示:

seriescollection vba

在MSDN的页面上,你可以找到很多例子。

(抱歉没有格式化,从我的手机输入)

答案 1 :(得分:0)

系列会有.Name.XValues和(Y).Values。你的代码混合了这一点。

改变这个:

With ActiveChart.SeriesCollection.XValues
    .Name = "Time"
    .Values = Xacross
End With

到此:

With ActiveChart.SeriesCollection
    .Name = "Time"
    .XValues = Xacross
    ' and perhaps you need to specify .Values = something?
End With
相关问题