Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert HEX to RGB in Excel

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

How can I convert a HEX to RGB, e.g. ff0000 to R=255, G=0, and B=0?

I know that the first 2 characters ff belongs to "R", the next 2 00 belongs to "G", and the final 2 00 belongs to "B". So I will have to use =LEFT(A1, 2) for "R", =RIGHT(LEFT(A1, 4), 2), and =RIGHT(A1, 2) for the last.

But how can I convert ff to 255 and 00 to 0, etc.? I guess I will have to do something to parse from hexadecimal (base 16) to decimal (base 10)?

I would like to do it without VBA.

like image 202
Jamgreen Avatar asked Aug 23 '17 07:08

Jamgreen


People also ask

How do I convert hex to RGB in Excel?

HexColorToRGB function: convert Hex color code to RGB format. XL. HexColorToRGB function – Text function type – сonverts a text string with Hex color code like #RRGGBB to its equivalent in RGB format.

How do you convert hex to RGB formula?

Converting hex to RGB We need to take two hex values for one RGB value, convert those two hex values to decimal values, and then perform the same step with the other values. We will get 3 values that correspond to RGB values.


2 Answers

You can try with the =Hex2Dec(A1) indeed, but you should split its input into 3 parts:

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

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

This is the result from the formula:

enter image description here

like image 116
Vityata Avatar answered Sep 18 '22 12:09

Vityata


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

=HEX2DEC(A1)

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

More details here.

like image 44
Diado Avatar answered Sep 20 '22 12:09

Diado