繁体   English   中英

如何根据单元格的值更改单元格颜色RGB值? (在Excel中)

[英]How can I make the cell colour RGB value change based on cell's value? (in Excel)

我是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

不要将ColorIndexRGB使用,而要使用Color

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM