Forum Discussion
Rao_Azeem
Dec 04, 2019Copper Contributor
background color code of a cell and get this color RGB properties in a cell
Hi, I want to know how can I get a cell background color code and get this color RGB properties in a cell
Riny_van_Eekelen
Dec 04, 2019Platinum Contributor
I believe you wish to read out the RGB code for the color of a particular cell. You need user a defined function in VBA to do this. Found the code on-line, here:
https://excelribbon.tips.net/T010180_Determining_the_RGB_Value_of_a_Color.html
Adopted it a bit so that it gives the output that you desire.
Function getRGB(rcell) As String
Dim C As Long
Dim R As Long
Dim G As Long
Dim B As Long
C = rcell.Interior.Color
R = C Mod 256
G = C \ 256 Mod 256
B = C \ 65536 Mod 256
getRGB = R & ";" & G & ";" & B
End Function
Enter a formula as usual, assuming the coloured cell is A1:
=getRGB(A1)
- Rao_AzeemDec 04, 2019Copper Contributorthanks got it