Excel has no native "random color" function, so to generate random colors in Excel you produce HEX, RGB, or HSL codes with an external tool and then apply those codes to cells using Conditional Formatting, Paste Special, or a short VBA snippet. The fastest workflow is to open the Random Color Generator, set the count to however many swatches you need (1 to 100), click Generate, and click any swatch to copy its HEX code into your clipboard; from there you paste the value into Excel the same way you would paste any other color reference.
Excel is excellent at handling random numbers (RAND, RANDBETWEEN, RANDARRAY) and it can read HEX strings, but it cannot on its own "roll a new color" the way a dedicated generator can. That gap is exactly what the Random Color Generator fills: it handles the visual picking, presents the result in three useful formats at once, and lets you copy any of them with a single click. The rest of this guide walks through the practical Excel side of the workflow, including the two main ways to apply a color in Excel (Conditional Formatting and Paste Special), how to automate it with VBA when you want randomness inside the spreadsheet itself, and how to avoid the most common mistakes people hit when they try to invent this from scratch.

Why Excel does not give you random colors out of the box
Excel's color system is tied to theme colors, standard palette colors, and any custom color you pick from the Colors dialog. Each of these is a fixed value stored against a workbook's theme or against the cell's Fill format. There is no function that "re-rolls" a color, and even the newer LAMBDA and LET functions do not include one. Functions like RANDBETWEEN can produce a random integer, which you can use to build a hex string, but you still have to parse and apply the result manually.
The practical workaround most users arrive at is to separate the two steps: generate the color somewhere that is good at it (a purpose-built tool), then feed the value into Excel. This keeps your workbook formula simple, your colors visually verifiable before they ever touch a cell, and your results reproducible because you can save the swatches you liked.
Generate the color codes with the Random Color Generator
- Open the Random Color Generator tool in your browser.
- In the count field, type how many swatches you want at once, anywhere from 1 to 100.
- Click Generate to produce a fresh batch of random HEX, RGB, and HSL colors.
- Click any swatch to copy its HEX code, or click the RGB or HSL value under it to copy that format instead.
- Switch back to Excel and paste the code where your workflow expects it (a cell, a Conditional Formatting rule, or a VBA constant).
Because the tool outputs all three formats side by side, you do not need to convert anything. If your Excel sheet uses conditional formatting with a hex code, use the HEX. If you are building an RGB triplet for VBA or for an image export, click the RGB line. If a downstream tool expects HSL, you have that too.
Apply a random color in Excel using Conditional Formatting
This is the most reliable non-coding approach and works in Excel for Microsoft 365, Excel 2021, Excel 2019, and Excel 2016.
- Select the range of cells you want to color, for example A2:A100.
- On the Home tab, click Conditional Formatting and choose New Rule.
- Choose Format only cells that contain, then set the condition to match the rows you want to color (such as "cell value greater than 0").
- Click Format, switch to the Fill tab, and click More Colors.
- In the Custom tab, paste your copied HEX value into the Hex field. Excel will accept the leading # automatically.
- Click OK, then OK again to apply the rule.
If you generated ten swatches and want each to apply to a different segment of your data, repeat the steps above once per segment, pasting the next HEX value at step 5. The Random Color Generator's count-of-100 limit means you can cover most rule sets in a single generation pass.
Apply a random color in Excel using Paste Special
Paste Special is the fastest method when you want to set the fill of an entire range at once without writing rules.
- In your workbook, set the fill of one cell to the color you generated (Home, Fill Color, More Colors, paste the HEX).
- Select that cell and press Ctrl+C to copy it.
- Select the target range, then press Ctrl+Alt+V to open Paste Special.
- Choose Formats and click OK. The fill color copies across the whole range.
This approach is also handy when you want one solid color rather than conditional behavior, and it avoids any formula overhead that could slow down large sheets.
Automate random colors in Excel with VBA
For users comfortable with the VBA editor, you can generate random colors inside Excel itself by calling the RGB function with three random integers between 0 and 255. The values themselves are not truly random without a seed, but for visual sampling they are more than random enough.
| Component | What it does | Example |
|---|---|---|
| Rnd() | Returns a Single value between 0 and 1 | Rnd() |
| Int(... * 256) | Scales that to an integer 0-255 | Int(Rnd() * 256) |
| RGB(r, g, b) | Combines the three channels into a Long color value | RGB(174, 92, 33) |
| .Interior.Color | Applies the color to a cell's fill | Range("A1").Interior.Color = RGB(...) |
A minimal macro that fills a range with random colors looks like this, applied to the selected range:
Sub RandomFillColors()
Dim cell As Range
For Each cell In Selection
cell.Interior.Color = RGB(Int(Rnd * 256), Int(Rnd * 256), Int(Rnd * 256))
Next cell
End Sub
Run this once and Excel colors every cell in your selection with an independently random fill. If you want hex strings alongside the fills (for documentation or reuse in another workbook), have the same loop write Hex(cell.Interior.Color) into the adjacent column.
Pick a format that matches your workflow
| Format | Best used for | Where it fits in Excel |
|---|---|---|
| HEX (e.g. #4A7C2E) | Web-style color references, Conditional Formatting custom colors, CSS exports | Custom tab of the Colors dialog |
| RGB (e.g. 74, 124, 46) | VBA macros, Power Query transforms, design tool imports | RGB() function inside VBA |
| HSL (e.g. 102, 47%, 33%) | Design systems that standardize on HSL for accessibility tweaking | Convert to RGB first with a tool, then apply |
The Random Color Generator shows all three together, so the choice is yours. If you need to convert between them later (for example, RGB to HEX to drop into a Conditional Formatting rule), the RGB to HEX tool handles that conversion in the browser without sending your values anywhere.
Save swatches you like instead of rerolling
Random color generators are intentionally random, which means rerunning them will almost never give you the same set twice. If you generate a batch and decide you want to keep it, copy the values into a "color library" sheet in your workbook before you close the generator. A simple two-column sheet (Name, HEX) gives you a reusable palette you can point Conditional Formatting rules at later. This is the same idea behind design system "token" files, just kept inside Excel where the rest of your project lives.
For projects that need a coordinated set rather than purely random swatches, pair the Random Color Generator with the Color Palette Generator: use the palette tool for the deliberate, harmonious base colors and the random tool for accents, highlights, or stress-test swatches. The two tools share the same click-to-copy behavior, so you can move between them quickly.
Common pitfalls when generating random colors in Excel
The most common mistake is assuming RANDBETWEEN(0, 16777215) on its own produces a usable color. It returns a decimal number that Excel can format as hex with the DEC2HEX function, but the result is a Long color value, not a string with a # prefix, and it does not look right when pasted into the Colors dialog without conversion. A second common issue is forgetting that Excel's standard palette only contains 56 theme colors plus whatever custom colors you add; if you generate a hex that is not in the theme, Excel will display it correctly only when you enter it through the Custom tab, not by picking from the swatch grid.
A third pitfall is volatility: any formula-based approach that calls RAND or RANDBETWEEN will recalculate every time the sheet recalculates, which means your colors can shift on every save or sort. If you need stable colors, generate them once with the tool, paste the HEX values as plain text into a helper column, and reference those static cells from your Conditional Formatting rules.
Finally, if your colors need to be accessible (legible text against the chosen fill), generate a few candidates and then check each pairing with the Color Contrast Checker before you commit. The checker evaluates any pair against the WCAG AA and AAA contrast thresholds, which matters even for internal spreadsheets that get printed or shared with screen reader users.
When to use random colors versus a curated palette
Random colors are not always the right choice. They work well for stress-testing conditional formatting rules, for highlighting outliers in a dataset, or for placeholder styling in a draft workbook. They are less suitable for client-facing reports or anything that will be printed, where visual consistency matters. For those cases, generate a few random candidates first to explore the space, then switch to the Color Palette Generator to lock in a coordinated set you actually want to ship. The two approaches complement each other: random for discovery, palette for commitment.
Putting it all together
For most users, the practical workflow is short: open the Random Color Generator, set a count, click Generate, click to copy the swatch in whichever format your workflow expects, then paste it into Excel through Conditional Formatting, Paste Special, or a VBA RGB() call. The tool handles the randomness and the formatting; Excel handles the application. That division of labor keeps both pieces simple, and it is the fastest way to get verifiable random colors into a spreadsheet without writing a custom function or maintaining a personal color library by hand.
If you build out the color library approach mentioned earlier, you can also pull related palettes for design work, such as the techniques described in Generate Random Colors for Design Projects in One Click, and reuse the same HEX values across Excel, CSS, and image exports. Random colors become far more useful once they are documented rather than regenerated.