7

我创建了一个 VBA for Excel 2007 程序,它可以根据活动工作簿中多达 52 个不同的选项卡自动为 ROI 创建条形图。我快完成了,唯一我不知道的是如何更改条形图的颜色。

这些图是在它们自己的子函数中创建的,通过这样的调用来调用。每个变量在被调用时都会发生变化。

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)我可以使用一个命令With来设置它,但是我花了太多时间试图弄清楚它,却一无所获。

4

3 回答 3

14

你有没有尝试过

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

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

于 2011-04-11T18:57:52.947 回答
4

它适用于我在非常相似的情况下的 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)
于 2013-06-21T09:15:40.387 回答
1

要更改集合中的不同栏,您可以使用:

ActiveChart.SeriesCollection(1).Points(1).Format.Fill.ForeColor.RGB = RGB(85, 142, 213)
ActiveChart.SeriesCollection(1).Points(2).Format.Fill.ForeColor.RGB = RGB(192,0, 0)
...

于 2019-09-12T15:43:25.640 回答