|
Kein さん ありがとうございました。
With MyCh.Axes(xlCategory)
にてエラーでしたので下記のように修正しました。
With MyCh.Chart.Axes(xlCategory)
無事に動いています。
ただし、表示領域をMyChart1ではA1:L15、MyChart2ではA17:L31に
設定したいのですが両方共A1:L15に表示されてしまいますなぜでしょうか?
またA39:K39に記載されている日付をグラフ横軸に表示したいのですが
どのようにすればよいでしょうか?
Sub MyChart1()
Dim Ch As ChartObject, MyCh As ChartObject
Dim Lp As Single, Wp As Single, Hp As Single
Dim i As Integer, j As Integer
With ActiveSheet
If .ChartObjects.Count > 0 Then
For Each Ch In .ChartObjects
If Ch.TopLeftCell.Address = "$A$1" Then
Ch.Delete
End If
Next
End If
With .Range("A1:L15")
Lp = .Left + 5
Wp = .Width - 10
Hp = .Height - 10
End With
Set MyCh = .ChartObjects.Add(Lp, 0, Wp, Hp)
MyCh.Chart.ChartType = xlLine
For i = 40 To 44
If Not IsEmpty(.Cells(i, 2).Value) Then
j = j + 1
MyCh.Chart.SeriesCollection.NewSeries _
.Formula = "=SERIES(," & .Name & "!$A$39:$K$39," & _
.Name & "!$A$" & i & ":$K$" & i & "," & j & ")"
End If
Next i
MyCh.Chart.HasTitle = True
MyCh.Chart.ChartTitle.Text = .Range("A38").Value
End With
With MyCh.Chart.ChartTitle
.Font.Size = 11
.Border.ColorIndex = 5
End With
With MyCh.Chart.Axes(xlCategory)
.HasTitle = True
.AxisTitle.Text = "DATE"
.AxisTitle.Font.Size = 11
End With
With MyCh.Chart.Axes(xlValue)
.HasTitle = True
.AxisTitle.Text = Range("b38").Value
.AxisTitle.Font.Size = 12
End With
Set MyCh = Nothing
End Sub
Sub MyChart2()
Dim Ch As ChartObject, MyCh As ChartObject
Dim Lp As Single, Wp As Single, Hp As Single
Dim i As Integer, j As Integer
With ActiveSheet
If .ChartObjects.Count > 0 Then
For Each Ch In .ChartObjects
If Ch.TopLeftCell.Address = "$A$17" Then
Ch.Delete
End If
Next
End If
With .Range("A17:L31")
Lp = .Left + 5
Wp = .Width - 10
Hp = .Height - 10
End With
Set MyCh = .ChartObjects.Add(Lp, 0, Wp, Hp)
MyCh.Chart.ChartType = xlLine
For i = 49 To 53
If Not IsEmpty(.Cells(i, 2).Value) Then
j = j + 1
MyCh.Chart.SeriesCollection.NewSeries _
.Formula = "=SERIES(," & .Name & "!$A$48:$K$48," & _
.Name & "!$A$" & i & ":$K$" & i & "," & j & ")"
End If
Next i
MyCh.Chart.HasTitle = True
MyCh.Chart.ChartTitle.Text = .Range("A47").Value
End With
With MyCh.Chart.ChartTitle
.Font.Size = 11
.Border.ColorIndex = 5
End With
With MyCh.Chart.Axes(xlCategory)
.HasTitle = True
.AxisTitle.Text = "DATE"
.AxisTitle.Font.Size = 11
End With
With MyCh.Chart.Axes(xlValue)
.HasTitle = True
.AxisTitle.Text = Range("b47").Value
.AxisTitle.Font.Size = 12
End With
Set MyCh = Nothing
End Sub
|
|