How to Convert Decimal to Hex with DEC2HEX in Excel

Turn a brand colour’s RGB values into hex pairs and a complete CSS colour code.

You will learn to

  • Convert a decimal number to hexadecimal
  • Pad hex output to two digits
  • Build a #RRGGBB colour code

How it works

DEC2HEX(number, [places]) converts a decimal integer into hexadecimal text: =DEC2HEX(126) returns 7E. Use the places argument to pad with leading zeros, so =DEC2HEX(9,2) returns 09 rather than 9.

That makes DEC2HEX ideal for colour codes: each RGB channel (0–255) becomes exactly two hex digits. Join them after a # to get a CSS colour: ="#"&DEC2HEX(R,2)&DEC2HEX(G,2)&DEC2HEX(B,2).

=DEC2HEX(B3,2)