Convert HEX to RGB in Excel

I have a column "HEX" and three columns "R", "G" and "B".

How to convert HEX to RGB (e.g. ff0000 to R = 255, G = 0 and B = 0)?

I know that the first 2 characters of "ff" belong to "R", the next 2 "00" belong to "G", and the final 2 "00" belongs to "B".

Therefore, I will have to use =LEFT(A1, 2)for "R", =RIGHT(LEFT(A1, 4), 2)and =RIGHT(A1, 2)for the latter.

But how to convert ffto 255and 00to 0, etc.? I think I have to do something to parse the hexadecimal (base 16) to decimal (base 10)?

I would like to do this without VBA.

+5
source share
3 answers

You can convert from hexadecimal to decimal using the HEX2DEC () function. For instance:

= HEX2DEC (A1)

If cell A1 contains the string "FF", this will return 255.

More details here: https://support.office.com/en-gb/article/HEX2DEC-function-8c8c3155-9f37-45a5-a3ee-ee5379ef106e

+6
source

You can really try with =Hex2Dec(A1), but you should divide its input into 3 parts:

One for R , one for G and one for B , given that you always get them in a format like this ff0000 .

=HEX2DEC(LEFT(B1,2))&"-"&HEX2DEC(MID(B1,3,2))&"-"&HEX2DEC(RIGHT(B1,2))

:

enter image description here

+6

Some pages do this ( w3SCHOOL PICKER ), but in excel you can do it

vba rgb to hex and reverse

If you try without vba, you can only use 56 colors. (when using colors from a cell)

+1
source

Source: https://habr.com/ru/post/1684281/


All Articles