Hex to RGB Excel Formula: Convert Color Codes in Your Spreadsheet
- Use the HEX2DEC function: =HEX2DEC(MID(A1,2,2)) extracts and converts the red channel.
- Full formula for all three channels: =HEX2DEC(MID(A1,2,2)) for R, =HEX2DEC(MID(A1,4,2)) for G, =HEX2DEC(MID(A1,6,2)) for B.
- Assumes the hex code in A1 starts with #. Strip the # first if needed with MID(A1,2,7).
- Use the free converter above for one-off lookups without touching Excel.
Table of Contents
Excel has no built-in hex-to-RGB function, but you can build one with two Excel functions you probably already know: MID() to extract each color channel as a two-character string, and HEX2DEC() to convert it from hexadecimal to a decimal number.
This comes up when you have a spreadsheet of brand colors in hex format and need to apply them as RGB values in a report, a data visualization, or a handoff document.
The Core Hex to RGB Formula in Excel
Assume your hex code is in cell A1, formatted as #3B82F6 (with the # symbol). Put these formulas in three separate cells:
- Red:
=HEX2DEC(MID(A1,2,2)) - Green:
=HEX2DEC(MID(A1,4,2)) - Blue:
=HEX2DEC(MID(A1,6,2))
The MID(text, start, length) function extracts two characters starting at position 2 (skipping the # sign). HEX2DEC() converts those two hex characters to a decimal integer. For #3B82F6, the results are 59, 130, and 246.
Adjusting the Formula for Hex Without the # Symbol
If your hex codes are stored without the # prefix (like 3B82F6), shift the MID start positions by one:
- Red:
=HEX2DEC(MID(A1,1,2)) - Green:
=HEX2DEC(MID(A1,3,2)) - Blue:
=HEX2DEC(MID(A1,5,2))
To handle both cases in one formula, normalize first: =HEX2DEC(MID(SUBSTITUTE(A1,"#",""),1,2)) strips the # if present before extracting.
Building an rgb() CSS String in Excel
To output the full CSS rgb() value as a single string in one cell, combine the formulas with CONCATENATE or the & operator:
="rgb("&HEX2DEC(MID(A1,2,2))&", "&HEX2DEC(MID(A1,4,2))&", "&HEX2DEC(MID(A1,6,2))&")"This produces a result like rgb(59, 130, 246) that you can paste directly into a CSS file or design tool input field.
Handling Errors and Edge Cases
HEX2DEC() only accepts valid hexadecimal characters (0-9 and A-F). Common issues:
- Lowercase letters: Wrap with UPPER() —
=HEX2DEC(UPPER(MID(A1,2,2))) - Short hex codes (#FFF): These need expansion. Three-character hex is not directly supported by this formula pattern.
- #NAME? error: HEX2DEC is part of the Analysis ToolPak in older Excel versions — enable it in Add-ins if you see this error.
For a quick one-off conversion, the free converter above is faster than debugging formula edge cases.
Need a Quick One-Off Conversion?
Skip the formula — paste your hex code above and copy the RGB values in one click.
Open Hex to RGB ConverterFrequently Asked Questions
Does HEX2DEC work in all versions of Excel?
HEX2DEC is included in all modern Excel versions (2007 and later) and in Excel 365. In very old versions it required the Analysis ToolPak add-in. It also works in Google Sheets without any add-in.
How do I convert RGB back to hex in Excel?
Use DEC2HEX() and pad to two characters with TEXT(): ="&TEXT(DEC2HEX(B1),"00")&TEXT(DEC2HEX(C1),"00")&TEXT(DEC2HEX(D1),"00") where B1, C1, D1 hold the R, G, B values.
Can I do this conversion in Google Sheets instead?
Yes. Google Sheets supports HEX2DEC() natively without any add-in, and the formulas work identically. See the dedicated Google Sheets guide for this conversion.
Is there a faster way to convert a whole column of hex codes?
Put the formula in the first row and drag the fill handle down to apply it to the entire column. Excel will automatically adjust the cell references for each row.

