![](/img/trans.png)
[英]How can I make a cell in Excel to change colour according to the value of other cell?
[英]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
不要将ColorIndex
与RGB
使用,而要使用Color
Cells(rwIndex, colIndex).Interior.Color = RGB(r, g, b)
假设当然r, g, b
都在(0,255)
范围内
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.