Excel 2007 VBA を使用して、同じデータ シートに ScatterSmoothNoMarkers タイプのグラフを作成しています。ソース データは、開いているテキスト ファイルの数に依存しています。Xvalue は固定 @ 位置 A2: A200 です。また、系列値の列の 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
どんな助けでも大歓迎です。