更改条形图中的条形颜色 – VBA Excel 2007

我已经为Excel 2007程序创build了一个VBA,可以根据活动工作簿中最多52个不同的选项卡自动为ROI创build条形图。 我已经接近完成了, 唯一无法弄清楚的是如何改变条形图的颜色。

这些graphics是在他们自己的子function中创build的,像这样调用。 每当variables被调用时,每个variables都会改变。

Call AddChartObject(1, 1, "Example", extraWeeks, weekDifference) 

我调用它的子集看起来像这样。

 Sub AddChartObject(j As Integer, k As Integer, passedChartTitle As String, xtraWks As Integer, ttlWks As Integer) Dim topOfChart As Integer topOfChart = 25 + (350 * j) 'Adds bar chart for total sales With ActiveSheet.ChartObjects.Add(Left:=375, Width:=475, Top:=topOfChart, Height:=325) .Chart.SetSourceData Source:=Sheets("Consolidation").Range("$A$" & 3 + ((17 + xtraWks) _ * j) & ":$C$" & (4 + ttlWks) + ((17 + xtraWks) * k)) .Chart.ChartType = xl3DColumnClustered .Chart.SetElement (msoElementDataLabelShow) .Chart.HasTitle = True .Chart.ChartTitle.Text = passedChartTitle & " Sales" .Chart.SetElement (msoElementLegendBottom) .Chart.SetElement (msoElementDataLabelNone) .Chart.RightAngleAxes = True End With End Sub 

根据市场营销的愿望,我想在条形图的SECOND系列上使用的RGB颜色是(155,187,89)。 我很确定有一个.chart。????。 = RGB(155,187,89)命令我可以在我的使用来设置这个,但我花了太多的时间试图弄清楚,只有拿出什么。

谢谢你的帮助!

@ScottyStyles:

你有没有尝试过

 .Chart.SeriesCollection([index]).Interior.Color = RGB(155, 187, 89) 

(其中[index]是您想要更改颜色的系列的占位符)?

它适用于我ScottyStyles在一个非常相似的情况下,但只为第一个系列收集。 我在下面使用了相同的权利,并没有改变SeriesCollection(2)的颜色。 那是一组线性数据。

 ActiveSheet.ChartObjects("Chart 1").Activate ActiveChart.ClearToMatchStyle ActiveChart.SeriesCollection(1).Interior.Color = RGB(85, 142, 213) ActiveChart.SeriesCollection(2).Interior.Color = RGB(192, 0, 0)