Forum Discussion
Radish_G
Oct 15, 2019Copper Contributor
Formula to find the cell color value (RGB & Color Index Value)
Hi Community, Is there any formula to find the cell colour value (RGB & Color Index Value) in Excel? Following image shows my requirement. Sample for Color Index Value (AutoCAD) ...
Subodh_Tiwari_sktneer
Oct 15, 2019Silver Contributor
You may use the following User Defined Function to get the Color Index or RGB value of the cell color.
Place the following function on a Standard Module like Module1...
Function getColor(Rng As Range, ByVal ColorFormat As String) As Variant
Dim ColorValue As Variant
ColorValue = Cells(Rng.Row, Rng.Column).Interior.Color
Select Case LCase(ColorFormat)
Case "index"
getColor = Rng.Interior.ColorIndex
Case "rgb"
getColor = (ColorValue Mod 256) & ", " & ((ColorValue \ 256) Mod 256) & ", " & (ColorValue \ 65536)
Case Else
getColor = "Only use 'Index' or 'RGB' as second argument!"
End Select
End Function
And then assuming you want to check the color index or the RGB of the cell A2, try the UDF on the worksheet like below...
To get Color Index:
=getcolor(A2,"index")
To get RGB:
=getcolor(A2,"rgb")