【发布时间】:2014-06-22 01:06:46
【问题描述】:
我正在使用 Excel 2007 VBA 在同一数据表中创建 ScatterSmoothNoMarkers 类型图表。我的源数据取决于打开的许多文本文件。 Xvalue 在位置 A2: A200 是固定的。 Series 值的列 ID 会发生变化。
如果我打开 2 个文件,我的源数据将是:Range(A2:A200, F2:G200)。要打开 3 个文件,我的源数据将是:Range(A2:A200, H2:J200)
等等......所以我需要用变量替换那些列的ID。但是在设置数据源时出现错误。
这是我的代码:
Sub addChart()
Dim n as integer ‘files count and also the number of columns for chart1
Dim intColStart, intColStop as integer ‘number of columns for chart 1
intColStart = n*2+2 ‘this is a formula to find the ID of the start column of chart1
intColStop = n*3+1 ‘this is a formula to find the ID of the stop column of chart1
…..
With ActiveSheet.ChartObjects.Add _
(Left:=100, Width:=375, Top:=75, Height:=225)
.Chart.SetSourceData Source:=Sheets("Sheet1").Range("A2:A200, intColStart:intColStop ") ‘’’’’PROBLEM RIGHT HERE‘’’’’’’
.Chart.ChartType = xlXYScatterSmoothNoMarkers
……..
End With
End Sub
任何帮助将不胜感激。
【问题讨论】: