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) Application.StatusBar = "-- チャート作成中 -- " Application.ScreenUpdating = False shname = ActiveSheet.Name 'グラフ作成 If evrb = 12 Then For i = 4 To GYOU Cells(i, 11) = Cells(GYOU + 4 - i, 10) Next Cells(3, 11) = Cells(3, 10) Set rangch = Union(Range(Cells(3, 1), Cells(GYOU, 1)), _ Range(Cells(3, 6), Cells(GYOU, 6)), _ Range(Cells(3, 9), Cells(GYOU, 9)), _ Range(Cells(3, 11), Cells(GYOU, 11))) Else Set rangch = Union(Range(Cells(3, 1), Cells(GYOU, 1)), _ Range(Cells(3, 6), Cells(GYOU, 6)), _ Range(Cells(3, 9), Cells(GYOU, 10))) End If 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.PlotArea.Select ActiveChart.SeriesCollection(3).Select ActiveChart.SeriesCollection(3).AxisGroup = 2 '左縦列文字調整 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 End With '左縦列文字調整 With ActiveChart.Axes(xlValue, xlSecondary) .TickLabels.Font.Size = 8 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 '終値の色 With ActiveChart.SeriesCollection(1) .Border.ColorIndex = 1 .Border.Weight = xlThick .Border.LineStyle = xlContinuous .MarkerStyle = xlNone End With '25日の色 With ActiveChart.SeriesCollection(2) .Border.ColorIndex = 5 .Border.Weight = xlMedium .Border.LineStyle = xlDot .MarkerStyle = xlNone End With '乖離率 With ActiveChart.SeriesCollection(3) .Border.ColorIndex = 3 .Border.Weight = xlMedium .Border.LineStyle = xlContinuous .MarkerStyle = xlNone End With Application.StatusBar = "-- チャート作成完了 -- " ActiveSheet.Protect DrawingObjects:=True Range("G1").Select End Sub