Blog
Wild & Free Tools

Hex to RGB Google Sheets Formula: Convert Colors in Spreadsheets

Last updated: February 2026 4 min read
Quick Answer

Table of Contents

  1. The Core Formula
  2. Hex Without the # Symbol
  3. Building an rgb() String
  4. Converting RGB Back to Hex
  5. Frequently Asked Questions

Google Sheets handles hex-to-RGB conversion with two built-in functions: MID() to extract each two-character color channel, and HEX2DEC() to convert from hexadecimal to decimal. No add-ons or custom scripts are needed.

This is useful when you have a column of brand colors in hex format and need to produce RGB values for a report, a design handoff, or downstream processing in another system.

The Core Hex to RGB Formula in Google Sheets

Assume your hex color is in cell A1, formatted as #3B82F6 (with the # symbol). Use three separate cells for the three channels:

For #3B82F6, these return 59, 130, and 246 — the correct RGB values. MID(text, start, length) extracts two characters starting at position 2 (skipping the # sign), and HEX2DEC() converts each pair from base 16 to decimal.

Adjusting for Hex Codes Without the # Prefix

If your hex codes are stored without the # symbol (as 3B82F6), adjust the start positions:

To handle both cases in a single formula that works regardless of whether the # is present, strip it first:

=HEX2DEC(MID(SUBSTITUTE(A1,"#",""),1,2))

SUBSTITUTE(A1,"#","") removes the # if it exists, then MID extracts from position 1.

Sell Custom Apparel — We Handle Printing & Free Shipping

Building a Full rgb() CSS String in One Cell

To combine all three values into a single CSS-ready string in one cell:

="rgb("&HEX2DEC(MID(A1,2,2))&", "&HEX2DEC(MID(A1,4,2))&", "&HEX2DEC(MID(A1,6,2))&")"

This returns a string like rgb(59, 130, 246) that you can copy directly into a CSS file or design tool.

To apply to a whole column, enter the formula in the first row and drag the fill handle down — Sheets automatically adjusts A1 to A2, A3, and so on.

Converting RGB Back to Hex in Google Sheets

The reverse direction uses DEC2HEX() with zero-padding to ensure each pair is always two characters wide:

="#"&TEXT(DEC2HEX(B1),"00")&TEXT(DEC2HEX(C1),"00")&TEXT(DEC2HEX(D1),"00")

Where B1, C1, D1 contain the R, G, B integers. TEXT(DEC2HEX(value), "00") converts to hex and pads with a leading zero if needed (for values less than 16, like 9, which becomes 09 rather than just 9).

Faster Than a Formula

For one-off conversions, paste your hex code above and copy the RGB values in under five seconds.

Open Hex to RGB Converter

Frequently Asked Questions

Does Google Sheets have HEX2DEC built in?

Yes. HEX2DEC is a native function in Google Sheets and requires no add-ons or extensions. It is also available in all modern versions of Microsoft Excel.

Why do I get a #NUM! error?

HEX2DEC throws #NUM! if the input contains invalid characters. Make sure the hex string contains only 0-9 and A-F (or a-f — both work). Wrap with UPPER() to normalize case: =HEX2DEC(UPPER(MID(A1,2,2))).

Can I do this conversion with an Apps Script instead?

Yes. A simple Apps Script function can convert an entire column at once: function hexToRgb(hex) { hex = hex.replace(/#/,""); return [parseInt(hex.slice(0,2),16), parseInt(hex.slice(2,4),16), parseInt(hex.slice(4,6),16)]; }. This may be faster for very large data sets.

Does this work on Google Sheets on mobile?

Yes. The HEX2DEC and MID functions work on Google Sheets for iOS and Android. You can enter formulas in the formula bar on mobile the same way as on desktop.

Andrew Walsh
Andrew Walsh Developer Tools & API Writer

Andrew worked as a developer advocate at two SaaS startups writing API documentation used by thousands of engineers.

More articles by Andrew →
Launch Your Own Clothing Brand — No Inventory, No Risk