棒グラフの色を変える
800の棒グラフがあり,要素ごとに色分けをする方法を調べてみた.
cells(i,2)に企業名がある.
あと,積み上げ式棒グラフの場合,SeriesCollection()で,何番目に積み上がっている棒グラフであるかと選択できる.
c=3から始まっているのは,ColorIndex=2は白色だから.
Sub ChangeColor() c = 3 For i = 1 To 882 Application.ScreenUpdating = False ActiveSheet.ChartObjects("グラフ 1").Activate ActiveChart.PlotArea.Select ActiveChart.SeriesCollection(1).Points(i).Select If Cells(i, 2).Value <> Cells(i + 1, 2).Value Then With Selection.Interior .ColorIndex = c End With c = c + 1 Else With Selection.Interior .ColorIndex = c End With End If Next i End Sub