To turn RGB channel values into a HEX color code inside a spreadsheet, combine Excel's DEC2HEX function with string concatenation, always passing 2 as the second argument so each channel becomes two hex digits: ="#"&DEC2HEX(R,2)&DEC2HEX(G,2)&DEC2HEX(B,2). HEX notation writes a color as #RRGGBB, where each pair is one RGB channel expressed in base 16 (00 to FF, which is 0 to 255 in decimal). A six-digit HEX can therefore describe 256 × 256 × 256 = 16,777,216 distinct colors — the same 24-bit space CSS, HTML, Figma, and Photoshop use, which is why translating between the two formats is such a common everyday task for developers and designers. Excel has no built-in RGB-to-HEX function, so DEC2HEX is the standard workaround: it converts a decimal integer into its hexadecimal text string, and concatenation stitches the three channels back together with a "#" prefix. The technique works whether your R, G, and B values sit in separate cells, in a single concatenated string you have to split first, or as literal numbers you type directly into the formula.

The trick that trips most people up is leading zeros. DEC2HEX(10) returns "A", not "0A", and a HEX code with missing digits is a different color from a fully padded one. Forcing two digits per channel with DEC2HEX(value, 2) fixes that, and once the formula is in place, the fastest sanity check is to drop the result into the RGB to HEX converter, which shows the swatch live and reports the matching HSL values, so you can confirm Excel produced the exact color you wanted before copying it into a stylesheet or a design file.

rgb to hex formula excel
RGB to HEX Formula in Excel: Step-by-Step Method

The Excel Formula for RGB to HEX

Excel's DEC2HEX function converts a decimal integer into a hexadecimal text string. The syntax is DEC2HEX(number, [places]), where places is the optional minimum number of characters to return. To build a complete HEX code from three separate RGB cells — for example, red in A2, green in B2, blue in C2 — enter the following formula in another cell:

="#"&DEC2HEX(A2,2)&DEC2HEX(B2,2)&DEC2HEX(C2,2)

For a single literal color such as the popular UI blue (59, 130, 246), the same shape works without cell references:

="#"&DEC2HEX(59,2)&DEC2HEX(130,2)&DEC2HEX(246,2)

That returns "#3B82F6", which is the CSS shorthand for the Tailwind blue-500 swatch. The arithmetic behind that result is straightforward: 59 in base 16 is 3B (3 × 16 + 11), 130 is 82 (8 × 16 + 2), and 246 is F6 (15 × 16 + 6); concatenated with the "#" prefix they form the six-digit code. Every RGB value must be an integer between 0 and 255; the browser tool clamps out-of-range or fractional inputs to the valid range instead of throwing an error, which is a useful safety net when you are copying channel values from a designer who rounded inconsistently. Users who want to understand the underlying math rather than the spreadsheet syntax can read the RGB to HEX formula guide, which walks through the same conversion by hand and makes it easier to debug the Excel formula when something looks wrong.

Set Up the Formula in a Spreadsheet

  1. Open a workbook and put the red, green, and blue channel values in three cells. For example, put 59 in A2, 130 in B2, and 246 in C2.
  2. Click an empty cell where you want the HEX code to appear and type the formula: ="#"&DEC2HEX(A2,2)&DEC2HEX(B2,2)&DEC2HEX(C2,2)
  3. Press Enter. Excel shows #3B82F6 in that cell, with the leading "#" and zero-padded channels.
  4. If you want lowercase output (the modern CSS convention), wrap the formula in LOWER: =LOWER("#"&DEC2HEX(A2,2)&DEC2HEX(B2,2)&DEC2HEX(C2,2))
  5. Drag the cell handle down to convert an entire column of RGB triples at once, or copy the formula across adjacent sheets with a single paste.
  6. To verify the result, paste the HEX string into the HEX field of the RGB to HEX converter and read the swatch and HSL readout next to it.

If you ever need to go the other direction — say, you pasted a HEX value from a stylesheet and want to read out the red, green, and blue channels in Excel — there is no clean built-in function for that either. HEX2DEC accepts only one channel at a time, so you would have to split the six-digit string, prefix each pair, and run HEX2DEC on the result, which is fragile and easy to miscount. The browser tool handles both directions in one place and accepts shorthand such as #abc by expanding it to #aabbcc automatically.

HEX Format Rules Excel Users Should Know

Before trusting any HEX string — whether it came out of Excel, a stylesheet, or a designer — it helps to know the rules the notation actually follows. The browser tool enforces these same rules, which is why its output always looks the same regardless of how you typed the input.

RuleBehaviorExample
Six-digit formTwo hex digits per channel, zero-paddedRGB (10, 0, 5) → #0A0005
Three-digit shorthandEach digit is doubled to expand the value#abc → #aabbcc; #f00 → #ff0000; #fff → #ffffff
Leading "#" optionalTool and CSS both accept it or skip it3b82f6, #3b82f6, and 3B82F6 all match
Case-insensitiveInput is matched regardless of letter caseABC, abc, and Abc resolve to the same color
Output normalizationAlways lowercase six-digit with padding0 renders as 00, never as a bare 0
Out-of-range channelsClamped to 0–255 instead of erroring300 → 255; -5 → 0
Malformed HEXFlagged clearly rather than silently wrongWrong length or illegal characters are rejected

Excel Formula vs. Browser Converter

Both methods produce the same color; the question is which one fits the workflow at hand. The table below compares the two approaches so you can pick the right tool for the job.

CriterionExcel DEC2HEX formulaBrowser RGB to HEX converter
Best forBatch-converting a column of RGB triples already in a sheetChecking a single HEX string, exploring HSL, or copying a CSS-ready value
Setup neededCells for R, G, B and the formula pasted inNone — open the page and start typing
Leading zero handlingManual via the ,2 argument; forget it and the code is silently too shortAutomatic — output is always normalized to lowercase six-digit form
Output caseUppercase by default (DEC2HEX returns A–F); wrap in LOWER for lowercaseAlways lowercase
Color previewNone — you only see the text resultLive swatch that updates as you type
HSL readoutNot providedIncluded alongside HEX and RGB
Privacy / data locationStays in your local workbookRuns entirely in JavaScript in your browser — nothing is uploaded
Three-digit shorthandExcel does not parse it — you would have to expand by handAccepted: #abc expands to #aabbcc

Verifying Excel Output and Common Reference Values

Once you have a HEX string from Excel, paste it into the HEX field of the converter and confirm the swatch matches the color you intended. The tool reports RGB, HEX, and HSL side by side, and a Copy button lets you grab whichever format you need. Because the conversion runs locally in JavaScript, no values are uploaded, which matters when you are working with an unreleased brand palette or a private design spec. The live preview also makes it obvious if Excel produced a malformed string — for instance, a forgotten comma in a cell reference would return "#VALUE!" inside Excel but would simply not parse on the converter page, which is a faster signal that something upstream needs fixing.

The values below are a quick sanity check. Each row is one of the standard reference colors used to confirm that Excel, the browser converter, and your stylesheet all agree on what the code means:

  • Black — RGB (0, 0, 0) → #000000
  • White — RGB (255, 255, 255) → #ffffff
  • Pure red — RGB (255, 0, 0) → #ff0000
  • Pure green — RGB (0, 255, 0) → #00ff00
  • Pure blue — RGB (0, 0, 255) → #0000ff
  • UI blue — RGB (59, 130, 246) → #3b82f6

Drop any of the HEX strings above into the converter to see the swatch and matching HSL. If you reproduce them in Excel with the formula from the previous section, the spreadsheet will return the same strings in uppercase — #3B82F6, for example — which is purely a casing difference and not a color difference, since HEX is case-insensitive and modern CSS treats "#3b82f6" and "#3B82F6" as the same value. The HSL readout is useful when you want to nudge a color lighter or more saturated without guessing at new channel numbers; convert the HEX back into HSL in the browser tool, change the saturation or lightness value, and read off the new HEX directly.

Related reading: RGB to HSV on Mac: Convert RGB Values in Your Browser.