Excel VBA Cell Text Color: Set, Read, and Reset

VBA & macros · Updated November 19, 2026

In Excel VBA, set a cell’s text color with its Font.Color property, usually assigning an RGB value: Range("B2").Font.Color = RGB(192, 0, 0). Use Font.ColorIndex for indexed or automatic colors, and remember that conditional formatting can determine the color Excel actually displays.

The basic VBA property for font color

Excel calls the text in a cell its font. VBA exposes that formatting through the cell’s Font object, so the standard pattern is a range reference, followed by .Font.Color, followed by a color value. The statement changes the font color; it does not change the cell’s fill, border, value, or number format.

For example, this macro colors cell B2 dark red on a worksheet named Sheet1:

Sub SetOneCellFontColor()
    Dim ws As Worksheet

    ' Set the font color of one cell.
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    ws.Range("B2").Font.Color = RGB(192, 0, 0)
End Sub

The worksheet is qualified through ThisWorkbook, which means the workbook containing the macro. That is safer than relying on whichever workbook or sheet happens to be active when the code runs. Replace Sheet1 and B2 with the actual sheet name and address in your file.

Before running a macro that changes formatting, save a copy of the workbook. VBA changes cannot be reversed with Ctrl+Z, so a backup is the simplest way to recover if the macro targets the wrong cells.

Apply a color to one cell or a range

The same property works on a single cell, a contiguous range, or a whole column. Assigning one color to a multi-cell range gives every cell in that range the same font color. For instance, ws.Range("A2:A20").Font.Color = RGB(0, 102, 204) colors the text in A2 through A20 blue. Qualify ws as a worksheet variable, as in the first example, or use a fully qualified worksheet reference.

When different cells need different colors, loop through the cells and make a decision for each one. This example colors negative numeric values in B2:B20 red and restores automatic font color for nonnegative numeric values:

Sub ColorNegativeValues()
    Dim ws As Worksheet
    Dim cell As Range

    ' Format numeric values only; leave text and blanks unchanged.
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    For Each cell In ws.Range("B2:B20").Cells
        If IsNumeric(cell.Value) And Len(cell.Value) > 0 Then
            If cell.Value < 0 Then
                cell.Font.Color = RGB(192, 0, 0)
            Else
                cell.Font.ColorIndex = xlColorIndexAutomatic
            End If
        End If
    Next cell
End Sub

The checks keep text and blank cells from being treated as numeric entries. Note that this example resets nonnegative numbers to automatic color, rather than restoring whatever custom color they had before. If preserving existing formatting matters, work on a copy or save the original colors separately before changing them.

RGB, ColorIndex, and theme colors

RGB(red, green, blue) is usually the clearest choice when you want a particular color. Each component is an integer from 0 to 255: RGB(255, 0, 0) is red, RGB(0, 0, 0) is black, and RGB(255, 255, 255) is white. You can use any combination of the three components to specify a color, which makes RGB convenient when matching a brand palette or applying consistent formatting in multiple workbooks.

Font.ColorIndex uses an indexed color rather than an explicit RGB value. It can be useful when working with older workbooks or when you specifically want an automatic font color. For example, cell.Font.ColorIndex = xlColorIndexAutomatic asks Excel to choose the default font color. The automatic choice may appear black or white depending on the cell’s background and display context. Indexed colors are less direct than RGB for matching an exact shade.

Excel also has theme colors, which connect formatting to the workbook’s theme. A theme color can change when someone changes the workbook theme, while an explicit RGB color remains the specified shade. VBA’s Font.ThemeColor property can assign a theme color, and Font.TintAndShade can adjust its tint or shade. Choose a theme color when the formatting should follow a document-wide design; choose RGB when the color itself must remain fixed.

A common misconception is that a number like 3 always means the same color when assigned to ColorIndex. Indexed colors depend on Excel’s indexed palette conventions and are not as self-explanatory or portable as an RGB triplet. For readable code, RGB makes the intended color much easier for another person to identify.

Read or reset a cell’s font color

You can read a cell’s color through the same Font.Color property. For one cell, the returned value represents its color and can be printed in the Immediate window or stored in a variable. VBA represents RGB color values as numbers, so the returned number may not look like a familiar hexadecimal color code at first glance.

Sub InspectFontColor()
    Dim ws As Worksheet
    Dim colorValue As Variant

    ' Read the current font color from one cell.
    Set ws = ThisWorkbook.Worksheets("Sheet1")
    colorValue = ws.Range("B2").Font.Color
    Debug.Print colorValue
End Sub

If a range contains cells with different font colors, do not assume that asking for the range’s single Font.Color gives a useful individual color for every cell. Inspect cells separately when the colors may differ. A loop is also the practical approach when you need to report or compare a range’s formatting cell by cell.

To return a cell to Excel’s automatic font color, use cell.Font.ColorIndex = xlColorIndexAutomatic. This is not necessarily the same as assigning black: automatic color lets Excel choose a suitable default, whereas RGB black explicitly requests black. It also does not remove other formatting such as bold, italic, or fill color. If you want to remove all direct formatting, that is a broader operation and should not be confused with resetting font color alone.

When conditional formatting controls the displayed color

A cell can have a font color assigned directly by VBA and also be covered by a conditional-formatting rule. In that situation, the color visible on the sheet may come from the rule, not from the direct font setting. This explains why a macro can run without an error yet the text appears to keep its old color or changes again when the cell value changes.

To inspect the rules in Excel for Microsoft 365 on Windows, select the relevant cells and choose Home > Conditional Formatting > Manage Rules. Check which rules apply to the selection and what font format they specify. You can edit or remove a rule there, or change the rule’s font format if the color should respond to cell values. Setting a static VBA font color is not a substitute for a rule that needs to update dynamically.

For example, use conditional formatting when negative values should always appear red as data changes. Use VBA when a macro needs to apply a one-time color, format a report as it is generated, or set a consistent appearance across a known range. If both mechanisms are present, decide which one should own the formatting; otherwise, later users may find the displayed result confusing.

Common problems and how to avoid them

  • The macro changes the wrong sheet. Unqualified references such as Range("B2") act on the active sheet in many contexts. Use a worksheet variable or qualify the reference with the intended workbook and sheet.
  • The color seems unchanged. Check conditional-formatting rules, and confirm that the text is not already the same color. Also confirm the macro ran and targeted the expected address.
  • The fill changes instead of the text. Font color uses .Font.Color; background fill uses .Interior.Color. They are separate properties.
  • The selected range has mixed formatting. A single range-level setting applies one color to all its cells. To make choices per cell, loop through the cells and evaluate each cell’s value or another condition.
  • The macro cannot be run in Excel for the web. Excel for the web can open and edit many macro-enabled workbooks, but it cannot run VBA macros. Use desktop Excel to run VBA.

Another practical issue is workbook scope. If the code is stored in a different workbook from the data, ThisWorkbook refers to the workbook containing the code, not necessarily the workbook currently being viewed. Choose the workbook reference deliberately, especially for reusable macros, and verify the sheet name before running the procedure.

Choosing between VBA and other ways to color text

VBA is useful when the formatting is part of a repeatable workflow: for example, a report macro might color headings, flag exceptions, or format a newly imported range. It can apply the same rule to many cells and can be rerun after data is refreshed. For a one-off change, selecting cells and using the Font Color control on the Home tab is often simpler and avoids macro security and maintenance concerns.

For colors that should change as values change, conditional formatting is usually a better fit. It keeps the rule visible in Excel’s interface and recalculates the appearance when the underlying values change. For a stable, one-time appearance, direct cell formatting or VBA may be more appropriate. The best method depends on whether the color is a fixed presentation choice or a live signal about the data.

Excel for Mac supports VBA, although some surrounding features and macro interfaces can differ from Windows. Excel for the web does not execute VBA, so a workbook that depends on macros must be opened in a desktop version to run them. If recipients need the formatting but do not need to run the macro, the applied cell formatting remains part of the workbook when it is saved.

Save and run macros safely

To write or edit VBA in desktop Excel for Microsoft 365 on Windows, open the Visual Basic Editor from the Developer tab, insert a standard module, and place the procedure there. If the Developer tab is not visible, enable it through File > Options > Customize Ribbon. On Mac, use the Developer tab’s Visual Basic command; the editor and some VBA capabilities can differ by platform, but the font-color properties shown here are standard Excel object-model properties.

If you want to keep the macro in the workbook, save it in a macro-enabled format such as .xlsm. A standard .xlsx file does not store VBA code. Only enable macros in files you trust, and avoid running an unfamiliar macro just because Excel displays a prompt. Since macro actions cannot be undone with Ctrl+Z, review the worksheet and target range, save a separate copy, and then run the code.

Frequently Asked Questions

How do I change text color in an Excel cell using VBA?
Assign a color to the cell’s font, for example Range("B2").Font.Color = RGB(255, 0, 0). In a macro, qualify the range with the intended worksheet so Excel does not apply the change to whichever sheet happens to be active.

What is the difference between Font.Color and Interior.Color?
Font.Color changes the text color. Interior.Color changes the cell’s fill or background color. They are separate formatting properties, so changing one does not automatically change the other.

How do I make cell text color automatic again?
Set cell.Font.ColorIndex = xlColorIndexAutomatic. This restores Excel’s automatic font-color choice; it is different from explicitly setting the font to black with an RGB value.

Why does VBA not change the color I see?
A conditional-formatting rule may be setting the displayed font color. Review the rules for the cell under Home > Conditional Formatting > Manage Rules, and change the rule if it should control the appearance.

Can VBA set different colors for cells in one range?
Yes. Loop through the cells and assign each cell’s Font.Color based on its value or another condition. Assigning one color to the entire range instead gives every cell the same font color.

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.