Sub 移動平均グラフ() Dim evra As String Dim evrb As Integer evra = Application.Version evrb = Val(Left(evra, 2)) Application.ScreenUpdating = False ActiveSheet.Unprotect 'チャート幅を確保 Rows("2:2").RowHeight = 260 shname = ActiveSheet.Name ' 旧グラフ削除 For Each zu In ActiveSheet.Shapes zu.Delete Next 'グラフ目盛り最小値 Set myrang = Range(Cells(4, 4), Cells(GYOU, 4)) yasune = Application.WorksheetFunction.Min(myrang) 'グラフ目盛り最大値 Set rangch = Union(Range(Cells(4, 5), Cells(GYOU, 5)), _ Range(Cells(4, 9), Cells(GYOU, 10))) takane = Application.WorksheetFunction.Max(myrang) takane = Int(Int(takane * 1.2) / 10) * 10 '移動平均データ If evrb = 12 Then For i = 4 To GYOU Cells(i, 11) = Cells(GYOU + 4 - i, 9) Cells(i, 12) = Cells(GYOU + 4 - i, 10) Next Cells(3, 11) = Cells(3, 9) Cells(3, 12) = Cells(3, 10) Set rangch1 = Range(Cells(3, 11), Cells(GYOU, 12)) Else Set rangch1 = Range(Cells(3, 9), Cells(GYOU, 10)) End If 'ローソク足作成 --------------------------------------------------- Set rangch = Union(Range(Cells(3, 1), Cells(GYOU, 1)), _ Range(Cells(3, 3), Cells(GYOU, 6))) Range("A4").Select ActiveSheet.ChartObjects.Add(5, 18, 550, 250).Select ActiveChart.SetSourceData Source:=rangch, PlotBy _ :=xlColumns ActiveChart.Location Where:=xlLocationAsObject, Name:=shname ActiveChart.ChartType = xlStockOHLC '左縦列文字調整 With ActiveChart.Axes(xlValue) .TickLabels.Font.Size = 8 If .MaximumScale < 1001 Then .MinimumScale = Int(Int(yasune * 0.8) / 10) * 10 Else .MinimumScale = Int(Int(yasune * 0.8) / 100) * 100 End If max1 = .MaximumScale min1 = .MinimumScale End With '下列文字調整 With ActiveChart.Axes(xlCategory).TickLabels .Font.Size = 8 .NumberFormatLocal = "yy/mm/dd" .Orientation = xlDownward End With 'データのある日のみ表示 ActiveChart.Axes(xlCategory, xlPrimary).CategoryType = xlCategoryScale 'グラフ線の調整 ActiveChart.ChartGroups(1).GapWidth = 50 'プロットエリアの色 ActiveChart.PlotArea.Interior.ColorIndex = 2 '軸の反転 With ActiveChart.Axes(xlCategory) .AxisBetweenCategories = True .ReversePlotOrder = True End With '東証平均の軸移動 With ActiveChart.Axes(xlValue) .TickLabelPosition = xlHigh .TickLabels.NumberFormatLocal = "#,##0" End With '移動平均グラフ作成 ----------------------------------------------------------- ActiveChart.SeriesCollection.Add Source:=rangch1, _ Rowcol:=xlColumns, SeriesLabels:=True, CategoryLabels:=False, Replace:= _ False ActiveChart.SeriesCollection(5).AxisGroup = 2 ActiveChart.SeriesCollection(6).AxisGroup = 2 '右縦列文字調整(第2軸 xlSecondary側) With ActiveChart.Axes(xlValue, xlSecondary) .MaximumScale = max1 .MinimumScale = min1 End With '凡例位置調整 ActiveChart.Legend.Position = xlBottom '5日の色 With ActiveChart.SeriesCollection(5) .Border.ColorIndex = 3 .Border.Weight = xlThin .Border.LineStyle = xlContinuous .MarkerStyle = xlNone End With '25日の色 With ActiveChart.SeriesCollection(6) .Border.ColorIndex = 50 .Border.Weight = xlThin .Border.LineStyle = xlContinuous .MarkerStyle = xlNone End With Application.StatusBar = "-- チャート作成完了 -- " ActiveSheet.Protect DrawingObjects:=True Range("G1").Select Application.ScreenUpdating = True End Sub