在条形图中更改条的颜色 [英] Changing color of Bars in a bar chart

查看:221
本文介绍了在条形图中更改条的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在excel中的代码来改变条形图的颜色,但它不工作。任何人都可以建议我在代码中做错了什么。

I have a code in excel to change colors of bar graph but its not working. Can anyone suggest me what I am doing wrong in the code.

With ActiveChart.SeriesCollection(1).Interior.Color = RGB(0, 153, 64)
End With

此代码不影响颜色

此外,对于所有条形(表示值0到200),我想要一种颜色(绿色),但是对于代表两个数据点(100和200)想要添加不同的颜色。任何人都可以告诉我如何使用VBA。

Also, For all bars (representing values 0 to 200) I want one color (green) but for two bars representing two data points (100 and 200), I want to add different color. Can anyone please tell me how to to that with VBA. I would appreciate your time regarding the same.

非常感谢

推荐答案

With语句指定要操作的对象或属性。您的代码应该是这样:

The With statement specifies the objects or properties to be acted on. Your code should be like this:

With ActiveChart.SeriesCollection(1)
    .Interior.Color = RGB(0, 153, 64)
End With

编辑 - 对于问题的第二部分:

EDIT - For the 2nd part of your question:

Sub ColorBars()
Dim chtSeries As Excel.Series
Dim i As Long

For Each chtSeries In ActiveChart.SeriesCollection
    With chtSeries
        For i = 1 To .Points.Count
            If .Values(i) = 100 Or .Values(i) = 200 Then
                .Points(i).Interior.Color = .Interior.Color = RGB(75, 172, 198)
            Else
                .Points(i).Interior.Color = RGB(0, 153, 64)
            End If
        Next i
    End With
Next chtSeries
End Sub

这篇关于在条形图中更改条的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆