|
▼のりっぺ さん:
ちょっと書き換えてみました。
(理解しやすいようにしたつもり)
Sub test()
Dim shn As String
Dim SC As Long, LC As Long
Dim i As Long
Dim 系列名 As String, X軸 As String, Y軸 As String, 系列番号 As Long
Dim 式 As String
shn = "Sheet1"
SC = 9
LC = 15
With ActiveSheet.ChartObjects(1).Chart
For i = 1 To 5
系列名 = shn & "!R6C" & i + 41 & ":R7C" & i + 41
X軸 = shn & "!R" & SC & "C1:R" & LC & "C1"
Y軸 = shn & "!R" & SC & "C" & i + 41 & ":R" & LC & "C" & i + 41
系列番号 = i
式 = "=SERIES(" & 系列名 & "," & X軸 & "," & Y軸 & "," & 系列番号 & ")"
.SeriesCollection(i).FormulaR1C1 = 式
Next
End With
End Sub
でも、わたしの場合、Formulaプロパティより
XValuesやValuesプロパティを使うほうが、わかりやすいです。
こんな書き方もあるという参考まで。
Sub test2()
Dim ws As Worksheet
Dim SC As Long, LC As Long
Dim X軸 As Range
Dim i As Long
Set ws = Worksheets("Sheet1")
SC = 9
LC = 15
Set X軸 = ws.Range("A" & SC & ":" & "A" & LC)
With ActiveSheet.ChartObjects(1).Chart
For i = 1 To 5
With .SeriesCollection(i)
.XValues = X軸
.Values = X軸.Offset(, i + 40)
End With
Next
End With
End Sub
|
|