Sub グラフデータ範囲を変数で指定して描画する()
Worksheets("Comparison").Activate 'シートをアクティブにする
右端列 = Range("C53").CurrentRegion.Columns.Count + 1 'アクティブセル領域の列数 +1
Range(Cells(53, 3), Cells(53, 右端列)).Copy '会社名をコピーする
Sheets("グラフ作成").Select
Range("A2").PasteSpecial Paste:=xlAll, _
Operation:=xlNone, SkipBlanks:=False _
, Transpose:=True '行列を入れ替えてすべて貼り付ける
Sheets("Comparison").Select
Range(Cells(12, 3), Cells(12, 右端列)).Copy '時間をコピーする
Sheets("グラフ作成").Select
Range("B1").PasteSpecial Paste:=xlAll 'すべて貼り付ける
Sheets("Comparison").Select
Range(Cells(49, 3), Cells(49, 右端列)).Copy '価格をコピーする
Sheets("グラフ作成").Select
Range("B2").PasteSpecial Paste:=xlAll
For コピー列 = 3 To 右端列 '価格を階段状にする
Range(Cells(2, コピー列), Cells(2, コピー列)).Cut
貼付行 = コピー列
Range(Cells(貼付行, コピー列), Cells(貼付行, コピー列)).Select
ActiveSheet.Paste
Next
'
Range(Cells(1, 1), Cells(貼付行, 右端列)).Select
'
Selection.Interior.ColorIndex = 2
Selection.Font.ColorIndex = 2
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Charts.Add
ActiveChart.ChartType = xlXYScatter
ActiveChart.SetSourceData Source:=Sheets("グラフ作成").Range("A1:E5"), PlotBy:= _
xlRows
ActiveChart.Location Where:=xlLocationAsObject, Name:="グラフ作成"
With ActiveChart.Axes(xlCategory)
.HasMajorGridlines = True
.HasMinorGridlines = False
End With
With ActiveChart.Axes(xlValue)
.HasMajorGridlines = True
.HasMinorGridlines = False
End With
ActiveChart.HasLegend = False
ActiveWindow.Visible = False
Range("N30").Select
End Sub
|