|
折れ線グラフの系列を変数"bou"にして太さと色を指定したく、下記のマクロを作ったのですが、別のシートから実行すると、
ActiveChart.SeriesCollection(a).XValues = "=gura!R5C1:R30C2"
の部分でエラーになります。シート名はその前に指定しているのに何故エラーになるかが分りません。ご指導宜しくお願いします。
Sub グラフ作成()
Dim endgyo, endretu As Integer
Dim hani As Range
Dim bou As Integer
Dim a As Integer
endgyo = Cells(65536, 2).End(xlUp).Row
endretu = Cells(4, 256).End(xlToLeft).Column
bou = endretu - 2
Set hani = Union(Range(Cells(4, 1), Cells(endgyo, 2)), Range(Cells(4, 3), Cells(endgyo, endretu)))
Worksheets("gura").Select
Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData Source:=hani, _
PlotBy:=xlColumns
For a = 1 To bou
ActiveChart.SeriesCollection(a).XValues = "=gura!R5C1:R30C2"
Next
ActiveChart.Location Where:=xlLocationAsObject, Name:="gura"
ActiveChart.SeriesCollection(bou).Select
With Selection.Border
.ColorIndex = 1
.Weight = xlMedium
.LineStyle = xlContinuous
End With
With Selection
.MarkerBackgroundColorIndex = 1
.MarkerForegroundColorIndex = 1
.MarkerStyle = xlDash
.Smooth = False
.MarkerSize = 3
.Shadow = False
End With
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "non-ZIF I型"
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
End With
ActiveChart.Axes(xlValue).MajorGridlines.Select
ActiveChart.PlotArea.Select
With Selection.Border
.ColorIndex = 16
.Weight = xlThin
.LineStyle = xlContinuous
End With
Selection.Fill.Patterned Pattern:=msoPattern50Percent
With Selection
.Fill.Visible = True
.Fill.ForeColor.SchemeColor = 35
.Fill.BackColor.SchemeColor = 2
End With
ActiveChart.Axes(xlValue).MajorGridlines.Select
With Selection.Border
.ColorIndex = 15
.Weight = xlHairline
.LineStyle = xlContinuous
End With
With ActiveChart.Axes(xlValue)
.MinimumScaleIsAuto = True
.MaximumScaleIsAuto = True
.MinorUnitIsAuto = True
.MajorUnitIsAuto = True
.Crosses = xlAutomatic
.ReversePlotOrder = False
.ScaleType = xlLinear
.DisplayUnit = xlNone
End With
ActiveChart.Axes(xlCategory).Select
Selection.TickLabels.AutoScaleFont = False
With Selection.TickLabels.Font
.Name = "Century Gothic"
.FontStyle = "標準"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
ActiveChart.Axes(xlValue).Select
Selection.TickLabels.AutoScaleFont = False
With Selection.TickLabels.Font
.Name = "Century Gothic"
.FontStyle = "標準"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
Selection.TickLabels.NumberFormatLocal = "0.0_ "
ActiveChart.Legend.Select
With Selection.Border
.Weight = xlHairline
.LineStyle = xlNone
End With
Selection.Shadow = False
Selection.Interior.ColorIndex = xlAutomatic
Selection.AutoScaleFont = False
With Selection.Font
.Name = "Century Gothic"
.FontStyle = "標準"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
Selection.Font.Bold = True
Selection.AutoScaleFont = False
With Selection.Font
.FontStyle = "太字"
.Size = 11
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
End Sub
|
|