차트의 시리즈/포인트 수를 반복하는 코드를 작성해야합니다. 아래의 코드는 차트의 각 시리즈 및/또는 포인트를 반복하며 동일한 채움 색상으로 모든 두 번째 막대의 서식을 지정합니다.
Sub ColorBarsInChart()
Dim i As Integer
Dim j As Integer
'Exit if no chart is selected
If Not (TypeName(Selection) = "ChartArea" Or TypeName(Selection) = "PlotArea") Then Exit Sub
'If only one series in chart
If ActiveChart.SeriesCollection.Count = 1 Then
For j = 1 To ActiveChart.SeriesCollection(1).Points.Count
If j Mod 2 Then
ActiveChart.SeriesCollection(1).Points(j).Format.Fill.ForeColor.RGB = RGB(255, 0, 0)
Else
ActiveChart.SeriesCollection(1).Points(j).Format.Fill.ForeColor.RGB = RGB(127, 127, 127)
End If
Next j
'If more than one series in chart
Else
For i = 1 To ActiveChart.SeriesCollection.Count
For j = 1 To ActiveChart.SeriesCollection(i).Points.Count
If i Mod 2 Then
ActiveChart.SeriesCollection(i).Points(j).Format.Fill.ForeColor.RGB = RGB(255, 0, 0)
Else
ActiveChart.SeriesCollection(i).Points(j).Format.Fill.ForeColor.RGB = RGB(127, 127, 127)
End If
Next j
Next i
End If
End Sub
특정 차트가 여러 데이터 시리즈로 구성되어 있는지 여부는 알 수 없으므로이 두 가지 경우 모두 사용할 수있는 코드 만 만들었습니다.
고맙지 만 작동하지 않습니다. 어쩌면 뭔가 빠졌을까요? Excel 2013에 있습니다. – Mikelowski
어떻게 작동하지 않습니까? 올바른 막대의 서식을 지정하지 않거나 오류를 반환합니까? –
매크로는 문제없이 실행되지만 필자가 시도한 예제의 세로 막 대형 차트에서는 아무런 색이 표시되지 않습니다. – Mikelowski