永发信息网

小白求教一个关于excel VBA的问题,我在excel中插入了一个散点图,VBA代码显示能正常运行,

答案:1  悬赏:50  手机版
解决时间 2021-02-06 06:57
  • 提问者网友:不爱我么
  • 2021-02-05 13:47
,修改了下用循环来做,就不行了,求问大神什么原因啊
Sub crbg()
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatterLines
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(1).Name = "='C'!$AF$6"
ActiveChart.SeriesCollection(1).XValues = "='C'!$AG$6:$AL$6"
ActiveChart.SeriesCollection(1).Values = "='C'!$AM$6:$AM$11"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(2).Name = "='C'!$AF$7"
ActiveChart.SeriesCollection(2).XValues = "='C'!$AG$7:$AL$7"
ActiveChart.SeriesCollection(2).Values = "='C'!$AM$6:$AM$11"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(3).Name = "='C'!$AF$8"
ActiveChart.SeriesCollection(3).XValues = "='C'!$AG$8:$AL$8"
ActiveChart.SeriesCollection(3).Values = "='C'!$AM$6:$AM$11"
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(4).Name = "='C'!$AF$9"
ActiveChart.SeriesCollection(4).XValues = "='C'!$AG$9:$AL$9"
ActiveChart.SeriesCollection(4).Values = "='C'!$AM$6:$AM$11"
End Sub

Sub 插入表格()
Dim i As Integer
i = 1
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlXYScatterLines
If i < 4 Then
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(i).Name = "='C'!$AF$(i+5)"
ActiveChart.SeriesCollection(i).XValues = "='C'!$AG$(i+5):$AL$(i+5)"
ActiveChart.SeriesCollection(i).Values = "='C'!$AM$6:$AM$11"
i = i + 1
End If
End Sub
最佳答案
  • 五星知识达人网友:持酒劝斜阳
  • 2021-02-05 14:27
下面三句代码有错:
ActiveChart.SeriesCollection(i).Name = "='C'!$AF$(i+5)"
    ActiveChart.SeriesCollection(i).XValues = "='C'!$AG$(i+5):$AL$(i+5)"
    ActiveChart.SeriesCollection(i).Values = "='C'!$AM$6:$AM$11"应该修改为:

ActiveChart.SeriesCollection(i).Name = "='C'!$AF$(" & (i+5) & ")"
    ActiveChart.SeriesCollection(i).XValues = "='C'!$AG$(" & (i+5) & "):$AL$(" & (i+5) & ")"
    ActiveChart.SeriesCollection(i).Values = "='C'!$AM$6:$AM$11"
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯