Determining Excel color from RGB and vice versa

Hello,

This is a follow-up question to a previous thread located here:

Auto-fill a cell's color based on numeric RGB values and vice versa in Excel

In that thread, the solution (by Ejgil Hedegaard) includes an attached Excel file in which the fill color of a particular cell, automatically changes in response to entering various values in three other cells labeled R (red), G (green), & B (blue).

This functionality is tremendously useful for me (and I suspect will be for others) because it enables you to instantly view the new color resulting from changes in any of the RGB parameters (ie without the necessity of the four clicks typically required to obtain that information):

        Home > Fill Color > More Colors > Custom

(The file also includes a chart for quickly converting from RGB decimal to RGB hex and vice versa.)

Additionally, the solution to the thread contains the formula for calculating Excel's color code:

        ExcelColor = R + G *256 + B *256^2

For example:

        Red = 204
        Green = 102
        Blue = 255

is calculated as follows:

        ExcelColor = 204 + (102*256) + (255*256^2)
        ExcelColor = 16737996

It also displays the following for reversing the process (ie :

        R = C Mod 256
        G = C \ 256 Mod 256
        B = C \ 256^2 Mod 256

Are these three formulas math or code and what is the purpose of the backslash?

It seems that to reverse the process, the =FLOOR() function should be used to first determine Blue, then Green and then Red as follows:

        ExcelColor = 16737996

        ExcelBlue = FLOOR(ExcelColor,256^2)
        ExcelBlue = 16711680

        Blue = 16711680 / 256^2
                Blue = 255

        Remainder = 16737996 – 16711680
        Remainder = 26316

        ExcelGreen = FLOOR(26316,256)
        ExcelGreen = 26112

        Green = 26112 / 256
                Green = 102

        Remainder = 26316 – 26112
        Remainder = 204

                Red = 204

How are these steps and the three equations/lines of code from the previous solution the same — assuming they are?

Thanks
WeThotUWasAToadAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ejgil HedegaardCommented:
The backslash means integer division, and can only be used in VBA.
Your calculation is correct, but can be simpler.
The similar formulas in Excel are
R=MOD(ColorCode,256)
G=MOD(INTColorCode/256),256)
B=MOD(INT(ColorCode/256^2),256)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WeThotUWasAToadAuthor Commented:
Thanks again Ejgil.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.