使条形图不同的颜色 [英] Make bar graphs different colors

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

问题描述

我有一个代码来改变我的条形图中的酒吧的颜色,但现在它给了我一个类型不匹配。请帮我修复我的代码。

I have a code to change the colors of my bars in my bar graph but now it gives me a type mismatch. Please help me fix my code.

Sub UpdateChart()

Dim myChartObj As ChartObject
Dim myChart As Chart
Dim mySeries(1 To 10) As Series
Dim myChartFormat(1 To 10) As ChartFormat
Dim myFillFormat(1 To 10) As FillFormat
Dim myColorFormat(1 To 10) As ColorFormat

ActiveSheet.ChartObjects(1).Activate

Set myChart = ActiveChart

For i = 1 To 10

    Set mySeries(i) = myChart.SeriesCollection(i)
    Set myChartFormat(i) = mySeries(i).Format
    Set myFillFormat(i) = myChartFormat(i).Fill
    Set myColorFormat(i) = myFillFormat(i).ForeColor


     If i = 1 Then

    myColorFormat(i).RGB = getRGB1(Cells(12, 7))

    ElseIf i = 2 Then

     myColorFormat(i).RGB = getRGB1(Cells(12, 7))

    ElseIf i = 3 Then

     myColorFormat(i).RGB = getRGB1(Cells(12, 8))

    ElseIf i = 4 Then

     myColorFormat(i).RGB = getRGB1(Cells(12, 9))

    ElseIf i = 5 Then

     myColorFormat(i).RGB = getRGB1(Cells(12, 10))

    ElseIf i = 6 Then

     myColorFormat(i).RGB = getRGB1(Cells(12, 11))

    ElseIf i = 7 Then

     myColorFormat(i).RGB = getRGB1(Cells(12, 12))

    ElseIf i = 8 Then

     myColorFormat(i).RGB = getRGB1(Cells(12, 13))

    ElseIf i = 9 Then

     myColorFormat(i).RGB = getRGB1(Cells(12, 14))

    ElseIf i = 10 Then

     myColorFormat(i).RGB = getRGB1(Cells(12, 15))

     End If




Next i



End Sub

Function getRGB1(rcell) As String
    Dim sColor As String

    sColor = Right("000000" & Hex(rcell.Interior.Color), 6)
    getRGB1 = Right(sColor, 2) & Mid(sColor, 3, 2) & Left(sColor, 2)
End Function


推荐答案

设置范围G12中每个单元格的颜色:R12

Set the color of each cell in range G12:R12

Option Explicit

Sub UpdateChart()
    Dim myChart As Chart

    Set myChart = ActiveSheet.ChartObjects(1)
    For i = 1 To 10
        With myChart.SeriesCollection(1)
            .Points(i).Format.Fill.ForeColor.RGB = Cells(12, i + 6).Interior.Color
        End With
    End Sub
End Sub

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

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