更改条形图中的条形颜色
我创建了一个 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
根据营销人员的意愿,我想在条形图中第二个系列上使用的 RGB 颜色是 (155, 187, 89)。我很确定有一个 .chart。???.???? = RGB (155, 187, 89)
命令我可以在我的 With
中使用它来设置它,但我花了太多时间试图弄清楚它,只是想出了没有什么。
I've created a VBA for Excel 2007 program that automatically creates bar graphs for ROI based on up to 52 different tabs in the active workbook. I'm close to done, and the only thing I cannot figure out is how to change the colors of the bargraphs.
The graphs are created in their own subfunction, called with a call like so. Every variable changes around whenever it's called.
Call AddChartObject(1, 1, "Example", extraWeeks, weekDifference)
My sub that it calls looks like this.
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
The RGB color I want to use on the SECOND series in the bar chart is (155, 187, 89), per marketing's wishes. I'm pretty sure there is a .chart.????.???? = RGB (155, 187, 89)
command I can use in my With
to set this, but I have spent far too much time trying to figure it out, only to come up with nothing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它适用于我的 ScottyStyles,情况非常相似,但仅适用于第一个系列集合。我在下面使用了相同的内容,并且没有改变 SeriesCollection(2) 的颜色。那是一组线性数据。
It works for me ScottyStyles in a very similar situation, but only for the first series collection. I used the same right below that, and that was not changing the color of the SeriesCollection(2). That one is a linear set of datas.
要更改集合中的不同条形,您可以使用:
to change different bars inside a collection you can use:
您是否尝试过
(其中 [index] 是您要更改颜色的系列的占位符)?
Have you tried
(where [index] is a placeholder for the series you want to change the color for)?