基于单元格的颜色图表行不与图表关联

我正在寻找一种自动化的方式来在Excel中根据与图表本身没有关联的单元格中的值和/或颜色对图表中的线条进行颜色设置。 基于价值的颜色是理想的解决scheme。

以下链接中图表的数据在单元格B2:F9中,我想要表示的颜色在行C1:F1上。 基于这个图像,我希望表示行C和E的图表行是绿色的,表示D和F的图表行是红色的。

在这里输入图像说明

为了给通过/失败部分上色,我目前有条件格式设置,但是能够改变这个以获得更有效的解决scheme。 这需要在大量的报告中缩放,所以手动换色不是一个可行的select。

任何援助将不胜感激。

这里有一些示例代码应该指向正确的方向。 它会根据电子表格中其他位置的值更改系列的颜色。 理想情况下,您可以修改此以适应您的需求。 我试图强调通过系列迭代和基于外部范围对它们着色的关键步骤。 还有其他关于select图表和范围的问题。

我正在使用“标题”单元格的值(通过/失败)来select颜色。 我认为通过条件格式(IIRC?)格式化单元格的Interior颜色可能很困难。

 Sub ColorChartBasedOnOtherCells() 'set up a range of colors that "matches" the series Dim rng_colors As Range Set rng_colors = Range("C1:F1") 'get a reference to the chart... assume it is selected for now Dim cht As Chart Set cht = ActiveChart Dim ser As Series Dim int_index As Integer 'iterate through series in order... assume this matches the column order int_index = 1 For Each ser In cht.SeriesCollection 'check the value of the "reference-color" cell and set series color If rng_colors(int_index) = "pass" Then ser.Format.Line.ForeColor.RGB = RGB(255, 0, 0) Else ser.Format.Line.ForeColor.RGB = RGB(0, 255, 0) End If int_index = int_index + 1 Next ser End Sub 

之前

在图表之前

以后颜色