RGB to Hue formula

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
This formula seems to work. But you beter test it. I'm no expert in this.

Code:
=IF(180/PI()*ATAN2(2*A2-B2-C2;SQRT(3)*(B2-C2))<0;180/PI()*ATAN2(2*A2-B2-C2;SQRT(3)*(B2-C2))+360;180/PI()*ATAN2(2*A2-B2-C2;SQRT(3)*(B2-C2)))
 
Upvote 0
This formula seems to work. But you beter test it. I'm no expert in this.

Code:
=IF(180/PI()*ATAN2(2*A2-B2-C2;SQRT(3)*(B2-C2))<0;180/PI()*ATAN2(2*A2-B2-C2;SQRT(3)*(B2-C2))+360;180/PI()*ATAN2(2*A2-B2-C2;SQRT(3)*(B2-C2)))

It errors on the semicolon
 
Upvote 0
Hello!
Here's the updated hue formula for the current version of office:
=MOD(180/PI()*ATAN2(2*A2-B2-C2,SQRT(3)*(B2-C2)),360)

Cells A2, B2, and C2 are the RGB values for the color.
A2 = Red
B2 = Green
C2 = Blue

For example:
12 20 255

This would give the result of hue being:
238.3396

This is a very precise measurement of hue.. which can be rounded to 238 instead of the long decimal value

Rounded would look like this for the formula:
=ROUND(MOD(180/PI()*ATAN2(2*A2-B2-C2,SQRT(3)*(B2-C2)),360),0)
 
Upvote 0
This formula seems to work. But you beter test it. I'm no expert in this.

Code:
=IF(180/PI()*ATAN2(2*A2-B2-C2;SQRT(3)*(B2-C2))<0;180/PI()*ATAN2(2*A2-B2-C2;SQRT(3)*(B2-C2))+360;180/PI()*ATAN2(2*A2-B2-C2;SQRT(3)*(B2-C2)))
Hello sir,

i would like you to know that the formula worked well and that i was able to use it in my database paper. I cited this thread in the paper and i am happy that the scientific community accepts this kind of information. here is the link to my paper The Development and Application of a HPTLC-Derived Database for the Identification of Phenolics in Honey. Thank you very much again
 
Upvote 0
Just for fun I thought I would expand on this and give a full RGB to HSV conversion formula. It gives you the option to return actual values or nicely formatted HSB values. It also avoids the use of ATAN, PI, SQRT, etc. hopefully to speed up calculation speed.

LAMBDA named formula RGB2HSB
Excel Formula:
=LAMBDA(
    red,green,blue,[strict],
        LET(
            r,red/255,
            g,green/255,
            b,blue/255,
            sq,SEQUENCE(3),
            fx,LAMBDA(a,b,c,CHOOSE(sq,a,b,c)),
            mx,MAX(r,g,b),
            d,mx-MIN(r,g,b),
            h,CHOOSE(XMATCH(mx,fx(r,g,b),0),(g-b)/d,2+(b-r)/d,4+(r-g)/d)*60,
            s,(d/mx),
                IF(strict,
                    fx(TEXT(h,"#°"),TEXT(s,"#,##0.0%"),TEXT(mx,"#,##0.0%")),
                    fx(h,s,mx)
                )
        )
)

RBG2HSB
ABCDEFG
1RGBStrict0
21220255Concise1
3
4
5StrictConcise
6Hue238.0247238°
7Saturation0.95294195.3%
8Brightness1100.0%
9
10
11StrictConcise
12Hue238.0247238°
13Saturation0.95294195.3%
14Brightness1100.0%
Data
Cell Formulas
RangeFormula
F6:F8F6=LET(r,A2/255,g,B2/255,b,C2/255,f,F1,sq,SEQUENCE(3),fx,LAMBDA(a,b,c,CHOOSE(sq,a,b,c)),mx,MAX(r,g,b),d,mx-MIN(r,g,b),h,CHOOSE(XMATCH(mx,CHOOSE(sq,r,g,b),0),(g-b)/d,2+(b-r)/d,4+(r-g)/d)*60,s,(d/mx),IF(f,fx(TEXT(h,"#°"),TEXT(s,"#,##0.0%"),TEXT(mx,"#,##0.0%")),fx(h,s,mx)))
G6:G8G6=LET(r,A2/255,g,B2/255,b,C2/255,f,F2,sq,SEQUENCE(3),fx,LAMBDA(a,b,c,CHOOSE(sq,a,b,c)),mx,MAX(r,g,b),d,mx-MIN(r,g,b),h,CHOOSE(XMATCH(mx,CHOOSE(sq,r,g,b),0),(g-b)/d,2+(b-r)/d,4+(r-g)/d)*60,s,(d/mx),IF(f,fx(TEXT(h,"#°"),TEXT(s,"#,##0.0%"),TEXT(mx,"#,##0.0%")),fx(h,s,mx)))
F12:F14F12=RGB2HSB(A2,B2,C2)
G12:G14G12=RGB2HSB(A2,B2,C2,F2)
Dynamic array formulas.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,561
Messages
6,179,522
Members
452,923
Latest member
JackiG

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top