Sub MACDグラフ() 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 ' 旧グラフ削除 For Each zu In ActiveSheet.Shapes zu.Delete Next shname = ActiveSheet.Name 'グラフ目盛り最小値 Set myrang = Range(Cells(4, 4), Cells(GYOU, 4)) yasune = Application.WorksheetFunction.Min(myrang) 'グラフ作成 If evrb = 12 Then For i = 4 To GYOU Cells(i, 14) = Cells(GYOU + 4 - i, 6) Next Else For i = 4 To GYOU Cells(i, 14) = Cells(i, 6) Next End If Cells(3, 14) = Cells(3, 6) Set rangch = Union(Range(Cells(3, 1), Cells(GYOU, 1)), _ Range(Cells(3, 11), Cells(GYOU, 14))) '6→14 ActiveSheet.ChartObjects.Add(5, 18, 550, 250).Select ActiveChart.ChartType = xlLineMarkers ActiveChart.SetSourceData Source:=rangch, PlotBy _ :=xlColumns ActiveChart.Location Where:=xlLocationAsObject, Name:=shname 'データのある日のみ表示 ActiveChart.Axes(xlCategory, xlPrimary).CategoryType = xlCategoryScale '軸の反転 With ActiveChart.Axes(xlCategory) .AxisBetweenCategories = True .ReversePlotOrder = True End With '第2グループへ分離 ActiveChart.SeriesCollection(4).AxisGroup = 2 '(1)→(4) '左縦列文字調整 With ActiveChart.Axes(xlValue, xlSecondary) .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 .TickLabels.Font.ColorIndex = 16 End With '左縦列文字調整 With ActiveChart.Axes(xlValue) .TickLabels.Font.Size = 8 .TickLabels.NumberFormatLocal = "0_ " End With '下列文字調整 With ActiveChart.Axes(xlCategory).TickLabels .Font.Size = 8 .NumberFormatLocal = "yy/mm/dd" .Orientation = xlDownward End With 'プロットエリアの色 ActiveChart.PlotArea.Interior.ColorIndex = 2 '凡例位置調整 ActiveChart.Legend.Position = xlBottom '終値 ActiveChart.SeriesCollection(4).Select '(1)→(4) With Selection.Border .ColorIndex = 16 .Weight = xlThin .LineStyle = xlContinuous End With With Selection .MarkerBackgroundColorIndex = 2 .MarkerForegroundColorIndex = 16 .MarkerStyle = xlDiamond .Smooth = False .MarkerSize = 4 .Shadow = False End With 'MACD With ActiveChart.SeriesCollection(1) '(2)→(1) .Border.ColorIndex = 10 .Border.Weight = xlThick .Border.LineStyle = xlContinuous .MarkerStyle = xlNone End With 'シグナル With ActiveChart.SeriesCollection(2) '(3)→(2) .Border.ColorIndex = 3 .Border.Weight = xlMedium .Border.LineStyle = xlContinuous .MarkerStyle = xlNone End With 'OSCI ActiveChart.SeriesCollection(3).ChartType = xlColumnClustered With ActiveChart.SeriesCollection(3).Select '(4)→(3) With Selection.Border .ColorIndex = 41 .Weight = xlMedium .LineStyle = xlContinuous End With Selection.Shadow = False Selection.InvertIfNegative = False With Selection.Interior .ColorIndex = 41 .Pattern = xlSolid End With End With '下文字位置調整 ActiveChart.Axes(xlCategory).Select With Selection.Border .Weight = xlHairline .LineStyle = xlAutomatic End With With Selection .MajorTickMark = xlInside .MinorTickMark = xlNone .TickLabelPosition = xlLow End With ActiveSheet.Protect DrawingObjects:=True Range("G1").Select End Sub