我目前正在使用以下代码:
Function InteriorColor(CellColor As Range)
Application.Volatile
InteriorColor = CellColor.Interior.ColorIndex
End Function
Sub Fillcolor()
For Each cl In [A3:D103]
If cl.Value <> "" Then
x = Application.WorksheetFunction.VLookup(cl.Value, Range("L1:M50"), 2, 0)
cl.Interior.ColorIndex = x
End If
Next
End Sub
此代码适用于某些颜色代码(来自调色板)单元格L1 -M50。
然而,我想根据特定单元格中的Hex或RGB值更改它。问题是我无法弄清楚如何。
答案 0 :(得分:0)
这是一个以各种格式返回单元格颜色的函数:
RGB
Public Function RetrieveColor(rI As Range, Opt As Integer) As String
Dim r As Range
Set r = rI(1)
Select Case Opt
Case 1
RetrieveColor = CStr(r.Interior.ColorIndex)
Case 2
RetrieveColor = CStr(r.Interior.Color)
Case 3
RetrieveColor = CStr(Hex(r.Interior.Color))
Case 4
v = r.Interior.Color
h = Hex(v)
nB = CStr(CLng("&H" & Mid(h, 1, 2)))
nG = CStr(CLng("&H" & Mid(h, 3, 2)))
nR = CStr(CLng("&H" & Mid(h, 5, 2)))
RetrieveColor = nR & "," & nG & "," & nB
End Select
End Function
答案 1 :(得分:0)
我通过将Interior.ColorIndex更改为Interior.Color来解决它。感谢aebailey。 之后,我可以使用RGBint作为颜色代码,它可以工作;)