Lesson#147: How to get color code in Excel

Lesson#147: How to get color code in Excel

Hello friends! How are you? Just working on a simple thing. I was making some easy formulas to get color code in Excel. Just like if you color a cell then this formula will break the R, G, and B values of the color.

Here is how you can make formulas to get color code in Excel.

get color code in Excel

First of all, I am going to insert a button from Developer Tab in the sheet. Then I will assign a simple macro to this button to get the decimal color code of any cell. For this, I will designate a cell to get the value. Here I will designate the cell C5.

Sub Button1_Click()
Range(“C5”).Value = ActiveCell.Interior.Color
End Sub

Now I will extract the values of Red, Green, and Blue from the decimal color code.

Before that, I want to let you know how we get the decimal color code from Red, Green, and Blue values. The formula is,

[RED] + [GREEN] * 256 + [BLUE] * 256 ^ 2

Now I will extract the value of RED with this formula in cell C2.

=MOD(C5,256)

Now in cell C3, I will extract the value of Green.

=MOD(C5-C2,256^2)/256

And in cell C4, I will extract the value of Blue with this formula.

=(C5-C2-C3*256)/256^2

I can easily make a Hexadecimal color code from these three values.

="#"&DEC2HEX(C2,2)&DEC2HEX(C3,2)&DEC2HEX(C4,2)

That will be easier to create the RGB color code.

="RGB("&C2&","&C3&","&C4&")"
get color code in Excel

That is how to get color code in Excel very easily. Here I am sharing the .xlsm file with you.

See also  Lesson#19: How to convert digit into word in excel

Hi! I am Puspendu. I am the founder and author of Excelabcd. I am little creative person, blogger and Excel-maniac guy. I hope you enjoy my blog.

Leave a Reply

Your email address will not be published. Required fields are marked *

*