在列表中交替出现两个颜色,与值无关

我有一个列/条形图,我想这样红和灰色的颜色:第一列红色,第二灰色,第三红色,第四灰色等,直到没有更多的价值观。 我正在努力与macroslogging器,因为它指定的每一点,但这个想法是,数据将被更新,并会根据情况改变点或值的数量更less或更多。

您需要编写一个循环遍历图表中的一系列/点的代码。 下面的代码循环遍历选定图表中的每个序列和/或点,并使用相同的填充颜色格式化每个第二个条。

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 

由于我不知道你的特定图表是否由多个数据序列组成,所以我已经使代码具有通用性,可以在两种情况下工作。