【问题标题】:How can I make the cell colour RGB value change based on cell's value? (in Excel)如何根据单元格的值使单元格颜色 RGB 值发生变化? (在 Excel 中)
【发布时间】:2018-08-10 19:56:51
【问题描述】:

我是 VBA 新手,尝试过以下方法,但不起作用。你能帮我修一下吗。我正在尝试根据其值使每个单元格具有不同的 RGB 颜色:

Sub ColorCells()

Dim rwIndex As Integer

Dim colIndex As Integer

Dim r As Integer
Dim g As Integer
Dim b As Integer


For rwIndex = 1 To 1000
        For colIndex = 1 To 1000

                r = Cells(rwIndex, colIndex).Value Mod 256
                g = Cells(rwIndex, colIndex).Value \ 256 Mod 256
                b = Cells(rwIndex, colIndex).Value \ 65536 Mod 256

                Cells(rwIndex, colIndex).Interior.ColorIndex = RGB(r, g, b)

        Next colIndex
Next rwIndex
End Sub

【问题讨论】:

    标签: excel colors cell rgb


    【解决方案1】:

    不要将ColorIndexRGB 一起使用,只需使用Color

     Cells(rwIndex, colIndex).Interior.Color = RGB(r, g, b)
    

    当然假设r, g, b都在(0,255)范围内

    【讨论】:

      猜你喜欢
      • 2017-11-11
      • 1970-01-01
      • 2016-12-12
      • 2013-06-10
      • 1970-01-01
      • 2017-05-20
      • 2019-10-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多