|
↓「グラフ作成1」ボタンに登録するコード
Sub MyChart1()
Dim Ch As ChartObject, MyCh As ChartObject
Dim Lp As Single, Wp As Single, Hp As Single
With ActiveSheet
If .ChartObjects.Count > 0 Then
For Each Ch In .ChartObjects
If Ch.TopLeftCell.Address = "$G$1" Then
Ch.Delete
End If
Next
End If
With .Range("G1:L9")
Lp = .Left + 5
Wp = .Width - 10
Hp = .Height - 10
End With
Set MyCh = .ChartObjects.Add(Lp, 5, Wp, Hp)
MyCh.Chart.ChartType = xlLine
For i = 49 To 53
If Not IsEmpty(.Cells(i, 2).Value) Then
With MyCh.Chart.SeriesCollection.NewSeries
.XValues = .Name & "!$A$48:$K$48"
.Values = .Name & "!$A$ & i & ":$K$" & i
End With
End If
Next i
MyCh.Chart.HasTitle = True
MyCh.Chart.ChartTitle.Text = .Range("A47").Value
End With
With MyCh.Chart.ChartTitle
.Font.Size = 15
.Border.ColorIndex = 5
End With
With MyCh.Axes(xlCategory)
.HasTitle = True
.AxisTitle.Text = "日付"
.AxisTitle.Font.Size = 12
End With
With MyCh.Axes(xlValue)
.HasTitle = True
.AxisTitle.Text = "データ2"
.AxisTitle.Font.Size = 14
End With
Set MyCh = Nothing
End Sub
↓「グラフ作成2」ボタンに登録するコード
Sub MyChart2()
Dim Ch As ChartObject, MyCh As ChartObject
Dim Wp As Single, Hp As Single
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:F9")
Wp = .Width - 10
Hp = .Height - 10
End With
Set MyCh = .ChartObjects.Add(5, 5, Wp, Hp)
MyCh.Chart.ChartType = xlLine
For i = 40 To 46
If Not IsEmpty(.Cells(i, 2).Value) Then
With MyCh.Chart.SeriesCollection.NewSeries
.XValues = .Name & "!$A$39:$K$39"
.Values = .Name & "!$A$ & i & ":$K$" & i
End With
End If
Next i
MyCh.Chart.HasTitle = True
MyCh.Chart.ChartTitle.Text = .Range("A38").Value
End With
With MyCh.Chart.ChartTitle
.Font.Size = 15
.Border.ColorIndex = 5
End With
With MyCh.Axes(xlCategory)
.HasTitle = True
.AxisTitle.Text = "日付"
.AxisTitle.Font.Size = 12
End With
With MyCh.Axes(xlValue)
.HasTitle = True
.AxisTitle.Text = "データ1"
.AxisTitle.Font.Size = 14
End With
Set MyCh = Nothing
End Sub
*提示された表では一部、行や列範囲があいまいなため、セルアドレスを推測で
指定しているところがあります。その点はそちらで正確に修正して下さい。
|
|