这里有一些小功能供您使用。从您的工作表中,按Alt-F11进入 VBA 编辑器,插入一个新模块,粘贴以下代码,返回您的工作表并按名称使用它们,例如=FillColor(A1)
前两个是承诺的“3-liners”,为字体和背景颜色提供十进制值 - 虽然不是很有用
第二对将十进制数转换为RGB,返回格式为N,N,N的字符串
第三对是数组公式- 连续选择 3 个单元格,输入公式并按Ctrl+ Shift+Enter以获得 3 个相邻单元格中的数字 RGB 值
Function FillColor(Target As Range) As Variant
FillColor = Target.Interior.Color
End Function
Function FontColor(Target As Range) As Variant
FontColor = Target.Font.Color
End Function
Function FillColorRGB(Target As Range) As Variant
Dim N As Double
N = Target.Interior.Color
FillColorRGB = Str(N Mod 256) & ", " & Str(Int(N / 256) Mod 256) & ", " & Str(Int(N / 256 / 256) Mod 256)
End Function
Function FontColorRGB(Target As Range) As Variant
Dim N As Double
N = Target.Font.Color
FontColorRGB = Str(N Mod 256) & ", " & Str(Int(N / 256) Mod 256) & ", " & Str(Int(N / 256 / 256) Mod 256)
End Function
Function FillColorRGBArray(Target As Range) As Variant
Dim N As Double, A(3) As Integer
N = Target.Interior.Color
A(0) = N Mod 256
A(1) = Int(N / 256) Mod 256
A(2) = Int(N / 256 / 256) Mod 256
FillColorRGBArray = A
End Function
Function FontColorRGBArray(Target As Range) As Variant
Dim N As Double, A(3) As Integer
N = Target.Font.Color
A(0) = N Mod 256
A(1) = Int(N / 256) Mod 256
A(2) = Int(N / 256 / 256) Mod 256
FontColorRGBArray = A
End Function
请注意:更改单元格的颜色不会通过上述函数/公式开始重新计算,因为通常不应该重新着色单元格来驱动重新计算。您必须使用Ctrl+ Alt+ Shift+手动启动完全重新计算F9