Excel VBA Change Cell Font Color: Code and Examples

VBA & macros · Updated November 19, 2026

To change a cell’s font color with Excel VBA, set the range’s Font.Color property, usually with the RGB function: Range("A1").Font.Color = RGB(255, 0, 0) makes the text in A1 red. In Excel for Microsoft 365 on Windows, put that statement in a VBA procedure and run the macro; the examples below show how to target cells, choose colors, and avoid common mistakes.

How VBA font color works

A cell’s font formatting is exposed through its Font object. The Color property sets or reads the font color, while Interior.Color controls the cell’s fill. These properties affect different parts of the cell: changing the font color does not change the background, and changing the fill does not recolor the characters.

Use a Range reference to identify the cell or cells, then set the font color. A range can be one cell, a rectangular group, a full column, or a row. For example, Range("A1:C10").Font.Color applies one color to every cell in that block. You can also refer to a worksheet explicitly, which is safer than relying on whichever sheet happens to be active.

VBA stores a font color as a color value. The most readable way to create a custom value is RGB(red, green, blue), where each component is an integer from 0 to 255. Red is RGB(255, 0, 0), black is RGB(0, 0, 0), and white is RGB(255, 255, 255). Combining the three components lets you choose many colors without looking up a numeric color code.

Set a specific cell or range

This example colors B2 blue on a worksheet named Sheet1. Change the sheet name, address, and RGB values to suit your workbook.

Sub ColorOneCell()
    Dim ws As Worksheet

    ' Set the target worksheet explicitly.
    Set ws = ThisWorkbook.Worksheets("Sheet1")

    ' Apply a blue font to cell B2.
    ws.Range("B2").Font.Color = RGB(0, 112, 192)
End Sub

To apply the same color to a range, replace "B2" with an address such as "B2:B20" or "A1:C10". The assignment sets the font color for all cells in the specified range. A whole column can be referenced as "B:B", but formatting an entire column may make the workbook larger or slower to process than formatting only the rows you use.

The worksheet qualification matters. A bare Range("B2") refers to the active sheet, which can change when a user clicks another tab. The explicit form, ws.Range("B2"), makes the target clear. The sheet name in the code must match a tab in the workbook; otherwise, the macro stops with a subscript out of range error. If the code is stored in a different workbook from the target sheet, select the correct workbook reference rather than assuming ThisWorkbook is the file you want.

Choose a color with RGB, named colors, or a theme

RGB is a good default when a macro needs a predictable color. It is easy to read later, and the numbers correspond to the red, green, and blue components. For instance, RGB(0, 128, 0) creates a medium green. You can use any three values from 0 through 255; values outside that range are not valid RGB component choices.

For basic colors, VBA also supplies named constants, including vbRed, vbBlue, vbGreen, vbBlack, and vbWhite. A line such as ws.Range("B2").Font.Color = vbRed is concise and clearly communicates the intent. The available named constants cover a limited set of basic colors, so use RGB when you need a particular shade.

Excel also supports theme colors. A font can use a theme color and a tint or shade so it can follow a workbook’s theme palette. One way to set a theme color is:

Sub UseThemeFontColor()
    Dim ws As Worksheet

    ' Use a theme accent color so the font follows the workbook theme.
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    ws.Range("B2").Font.ThemeColor = xlThemeColorAccent1
End Sub

Theme colors can be useful in a workbook designed around a consistent palette. If the theme changes, theme-based formatting can reflect that change, whereas a fixed RGB value remains the same color. Use RGB when exact, independent color is more important; use a theme color when the font should fit the workbook’s theme. If you need a lighter or darker theme variation, the font object also has a TintAndShade property, but its values and visual effect should be checked against the workbook’s theme.

Color cells conditionally with a macro

A macro can inspect values and format only the cells that meet a condition. The following example colors numeric values below zero red in B2:B20 and colors other numeric values green. Blank cells and text are left unchanged. It explicitly checks for error values before examining the cell value.

Sub ColorValuesBySign()
    Dim ws As Worksheet
    Dim cell As Range
    Dim target As Range

    ' Set the worksheet and the cells to inspect.
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    Set target = ws.Range("B2:B20")

    ' Color numeric values according to their sign.
    For Each cell In target.Cells
        If Not IsError(cell.Value) Then
            If IsNumeric(cell.Value) And Len(cell.Value) > 0 Then
                If CDbl(cell.Value) < 0 Then
                    cell.Font.Color = RGB(192, 0, 0)
                Else
                    cell.Font.Color = RGB(0, 128, 0)
                End If
            End If
        End If
    Next cell
End Sub

The test for IsError prevents an error value such as #N/A from being passed to later checks. IsNumeric allows numeric values, including numbers returned by formulas. This sample colors zero green because zero is not less than zero; change the comparison if zero should have its own treatment. The code leaves existing formatting untouched for blanks and text, so those cells may retain whatever font color they already had.

For formatting that should update automatically whenever cell values change, Excel’s Conditional Formatting feature is often a better choice than a one-time macro. A macro runs when called; it does not automatically keep its result synchronized with later edits unless you add event code or run the macro again. Conditional formatting is designed to recalculate its appearance as the values it monitors change.

Run and save the VBA macro

In Excel for Microsoft 365 on Windows, open the workbook and press Alt+F11 to open the Visual Basic Editor. Choose Insert > Module, paste the procedure into the module, and edit the sheet name and range. Return to Excel, press Alt+F8, choose the macro, and select Run. You can also use Developer > Macros if the Developer tab is visible.

On Mac, use Option+F11 to open the Visual Basic Editor; on some keyboards, you may also need the Fn key. The Developer tab’s Macros command is available for running macros, and the keyboard shortcut for opening the macro dialog can vary with the keyboard and Excel settings. Excel for the web can open a workbook containing VBA, but it cannot create, run, or edit VBA macros. Open the file in the desktop Excel app to use this code.

Save a workbook that contains VBA as an Excel Macro-Enabled Workbook (.xlsm) if you want to preserve its macro. A standard .xlsx file does not store VBA code. Excel may also show a security warning before allowing macros to run; only enable macros in files you trust and that you expected to receive. Before running a macro, save a copy of the workbook. VBA changes cannot be undone with Ctrl+Z, so a backup gives you a way to restore the original formatting if the code targets the wrong cells.

Common problems and how to fix them

  • The macro reports a missing worksheet. Check the worksheet tab name used in ThisWorkbook.Worksheets("Sheet1"). The name must match exactly, including spaces. If the target is in another open workbook, reference that workbook instead.
  • The wrong sheet or cells change. Avoid relying on an unqualified Range or on the current selection. Specify both the worksheet and the range, and verify the address before running code that changes many cells.
  • The font color seems unchanged. Check that the code changes Font.Color, not Interior.Color. Also inspect Conditional Formatting rules: a rule can control the displayed font formatting and make the result appear different from a direct format assignment.
  • Only some cells appear to have one color. If a range already contains mixed font colors, reading its Font.Color may not return one simple color value. Setting the property on the entire range, however, applies the assigned color to all cells in that range.
  • The macro will not run. Confirm that the file is open in desktop Excel, saved in a macro-capable format, and that macros are permitted by the workbook’s security settings. Excel for the web does not execute VBA.

Another frequent mix-up is expecting font color to change the cell background. Use Font.Color for letters and numbers; use Interior.Color for the fill. For example, ws.Range("B2").Interior.Color = RGB(255, 255, 0) makes the cell fill yellow but does not set the font color. You can set both properties if the design requires contrasting text and background, but choose colors with enough contrast to remain readable.

VBA formatting versus Conditional Formatting

Direct VBA formatting is appropriate when the color is a deliberate, fixed result of a macro—for example, applying a standard font color to a report before it is distributed. The formatting remains until another action changes it. It is also useful when a larger VBA routine is already building or cleaning up a worksheet.

Conditional Formatting is usually preferable when color represents a changing status, such as values below a threshold or duplicate entries. In Excel for Windows, select the cells and use Home > Conditional Formatting to create a rule. Excel applies the appearance when the rule is true and updates it as relevant values change. A macro that sets Font.Color does not, by itself, create a live rule.

These approaches can coexist, but they can make troubleshooting less obvious. Conditional Formatting may visually override direct font formatting while its rule applies. If the color shown does not match the VBA assignment, inspect the rules for the affected range through Home > Conditional Formatting > Manage Rules. Decide which method should control the appearance, and avoid adding overlapping rules unless their priority and purpose are clear.

Frequently Asked Questions

What is the VBA code to make a cell’s font red?
Use Range("A1").Font.Color = RGB(255, 0, 0) inside a macro to make A1’s text red. Qualify the range with a worksheet, such as ws.Range("A1"), when you want to make the target explicit.

How do I change the font color of multiple cells?
Set Font.Color on a multi-cell range, for example ws.Range("A1:C10").Font.Color = RGB(0, 0, 255). Every cell in that range receives the same font color.

How do I change font color based on a cell’s value?
Loop through the target range, test each cell’s value with VBA conditions, and set cell.Font.Color when the condition is met. For a color that should update automatically as values change, consider Conditional Formatting instead.

Why does my VBA font color not show?
Check the range and worksheet references, confirm that the assignment uses Font.Color, and look for Conditional Formatting rules that may affect the displayed font. Also verify that the macro ran in desktop Excel without an error.

Can I change cell font color with VBA in Excel for the web?
No. Excel for the web does not run VBA macros. Open the workbook in desktop Excel for Microsoft 365 on Windows or Mac to run the macro; the workbook can still be stored online.

Can I undo a VBA font-color change with Ctrl+Z?
No. Running VBA clears Excel’s normal undo history, so Ctrl+Z cannot reverse the macro’s formatting change. Save a separate copy before running code that changes a range.

Related

Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.

More in VBA & macros

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.