Excel VBA Range Interior Color: Set and Read Cell Fills

VBA & macros · Updated November 3, 2026

Excel VBA Range Interior Color: Set and Read Cell Fills

In Excel VBA, use the Interior.Color property to set or read a cell’s fill color: for example, Range("A1").Interior.Color = RGB(255, 0, 0) fills A1 red. You can apply the same property to a range, use ColorIndex for palette-based colors, or clear a fill with xlColorIndexNone.

What Range.Interior.Color controls

A cell’s Interior object represents its background fill formatting. It is separate from the cell’s value, number format, border, and font. In VBA, the Color property sets or returns a color value, and the RGB function makes it straightforward to specify a color using red, green, and blue components.

For instance, with a worksheet active, this statement colors A1 green:

Sub FillOneCell()
    ' Set A1's fill to green.
    Range("A1").Interior.Color = RGB(0, 176, 80)
End Sub

The three RGB arguments are integers from 0 to 255: the first is red, the second green, and the third blue. RGB(255, 0, 0) is red, RGB(0, 0, 255) is blue, and RGB(255, 255, 0) is yellow. This is usually clearer and more portable than trying to remember a numeric color value.

For more reliable code, qualify the range with a worksheet or workbook. An unqualified Range("A1") refers to the active sheet, so a user changing sheets could cause the macro to format the wrong cell. A qualified reference makes the target explicit:

Sub FillNamedSheetCell()
    ' Target the worksheet by its tab name.
    ThisWorkbook.Worksheets("Report").Range("A1").Interior.Color = RGB(0, 176, 80)
End Sub

Set a fill for one cell or a range

To color multiple cells uniformly, assign the property to a multi-cell range. Excel applies that fill to each cell in the specified area:

Sub FillRange()
    ' Apply a pale blue fill to a block of cells.
    ThisWorkbook.Worksheets("Report").Range("B2:D8").Interior.Color = RGB(221, 235, 247)
End Sub

Range references can also be built from variables, named ranges, or a last-used row. For example, suppose report data begins in row 2 and column B contains a value for every data row. The following procedure colors B2:B through the last populated cell in column B:

Sub FillThroughLastRow()
    Dim ws As Worksheet
    Dim lastRow As Long

    Set ws = ThisWorkbook.Worksheets("Report")
    lastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row

    ' Avoid formatting the heading if there are no data rows.
    If lastRow >= 2 Then
        ws.Range("B2:B" & lastRow).Interior.Color = RGB(255, 242, 204)
    End If
End Sub

This technique finds the last nonblank cell in column B by moving upward from the bottom of the worksheet. If your chosen column can contain gaps or may be blank even when other columns have data, find the last row using a column that reliably contains a value, or use a different method suited to the layout.

Choose between RGB, ColorIndex, and theme colors

Interior.Color is generally the most convenient choice when you know the exact RGB shade. It lets you specify custom colors rather than selecting only from a fixed list. It is also useful when you want consistent output across workbooks and do not need the fill to change with a workbook’s theme.

Interior.ColorIndex refers to an indexed color rather than directly specifying RGB components. It can be useful in older workbooks or code that already uses the indexed palette, but it is less descriptive: a number such as 6 does not communicate the intended color as clearly as an RGB expression. To remove a cell’s fill, use the special constant xlColorIndexNone:

Sub ClearCellFill()
    ' Remove the fill from A1 without changing its value or other formatting.
    ThisWorkbook.Worksheets("Report").Range("A1").Interior.ColorIndex = xlColorIndexNone
End Sub

A theme color is another option when fills should follow the workbook’s design. For example, assigning ThemeColor selects a theme slot, while TintAndShade adjusts its lightness or darkness. A theme-based fill can adapt if the workbook theme changes; a fixed RGB fill is better when the exact color must stay constant. Use a theme color only when that relationship to the workbook theme is wanted.

Sub ApplyThemeFill()
    With ThisWorkbook.Worksheets("Report").Range("C3").Interior
        ' Use the workbook's first accent color with a lighter tint.
        .ThemeColor = xlThemeColorAccent1
        .TintAndShade = 0.4
    End With
End Sub

Theme color names such as xlThemeColorAccent1 are built-in Excel VBA constants. The resulting appearance depends on the active workbook theme, so the exact visible shade may differ between workbooks.

Read a cell’s fill color in VBA

To inspect a fill, read Interior.Color into a variable. It returns a numeric color value, which can be printed in the Immediate window or used in a comparison. The following example reads B2:

Sub ReadCellFill()
    Dim fillValue As Variant

    fillValue = ThisWorkbook.Worksheets("Report").Range("B2").Interior.Color
    Debug.Print fillValue
End Sub

In the Visual Basic Editor, the Immediate window can display output from Debug.Print. If you need a human-readable label, compare the returned value with an RGB value. For example, with the target cell at B2, compare its fill against RGB(255, 0, 0) to check for red. Do not assume that a numeric color value is itself a descriptive color name.

Reading a multi-cell range requires more care than reading one cell. If cells have different fills, the range does not have one meaningful uniform color to report. Test cells individually when you need to identify differences, or first make the range uniform. A cell with no fill may also not behave like a deliberately applied white fill; these are visually similar in some contexts but are distinct formatting states.

Fill color is not the same as pattern or font color

The Interior object also has properties for fill patterns. Setting only Color changes the fill color; it does not set the font color. To change the text color, use the cell’s Font.Color property instead. For example, with A1 as the target, Range("A1").Font.Color = RGB(255, 255, 255) makes its text white, while Range("A1").Interior.Color = RGB(0, 0, 0) makes its fill black.

Pattern settings matter when a cell uses a patterned fill rather than a solid one. The Pattern property controls the fill pattern, and the PatternColor property controls the pattern’s foreground color. A pattern can make a cell’s appearance more complex than one background color, so setting only Interior.Color may not produce the visual result you expect if an existing pattern remains. For a plain solid fill, explicitly set the pattern to xlSolid:

Sub SetSolidFill()
    With ThisWorkbook.Worksheets("Report").Range("D4").Interior
        ' Set both the fill style and its color.
        .Pattern = xlSolid
        .Color = RGB(255, 242, 204)
    End With
End Sub

Conditional formatting can change the displayed color

A common source of confusion is that a cell’s visible fill may come from conditional formatting rather than ordinary cell formatting. Range("A1").Interior.Color reads or sets the cell’s direct fill formatting. It does not necessarily return the color currently shown because a conditional formatting rule takes precedence in the display.

In a VBA macro, Range("A1").DisplayFormat.Interior.Color can be used to read the displayed fill, including the effect of conditional formatting. This is useful when checking what a user sees, but it is not a replacement for editing the rule itself. To change conditional formatting, inspect or modify the cell’s conditional formatting rules rather than assigning a direct fill that may remain hidden beneath the rule. Also, DisplayFormat is intended for VBA procedures, not as a normal worksheet formula function.

Common errors and safe macro use

  • Wrong sheet: An unqualified Range uses the active worksheet. Use ThisWorkbook.Worksheets("Report").Range("A1") when that is the intended location.
  • Wrong property: Font.Color changes text, while Interior.Color changes the cell fill.
  • Unexpected visible result: Check for conditional formatting or a pattern that affects the displayed fill.
  • Macros unavailable: VBA macros cannot run in Excel for the web. Use the desktop Excel app for Windows or Mac to run VBA.
  • Macro not saved: Save a workbook containing VBA as an Excel Macro-Enabled Workbook (.xlsm) if you want to retain its macro code.

In Excel for Microsoft 365 on Windows, open the Visual Basic Editor from the Developer tab, then run a procedure from the editor or use Alt+F8 to open the Macro dialog. If the Developer tab is hidden, enable it through File > Options > Customize Ribbon. Excel for Mac also supports VBA in the desktop app, although its ribbon and keyboard shortcuts can differ; Excel for the web does not run VBA macros.

Before running a macro that changes formatting, save a copy of the workbook. Macro changes cannot be undone with Ctrl+Z, so a backup is the simplest way to recover if the code targets the wrong range. Only enable macros in files from sources you trust, and review code before running it.

Frequently Asked Questions

How do I change a cell’s background color with VBA?
Assign an RGB value to the cell’s Interior.Color property. For example, with A1 as the target, Range("A1").Interior.Color = RGB(255, 0, 0) sets its fill to red.

How do I color an entire row or column?
Use a row or column range, such as Rows(2).Interior.Color = RGB(255, 242, 204) for row 2, or Columns("C").Interior.Color = RGB(221, 235, 247) for column C. Qualify the row or column through the intended worksheet to avoid relying on the active sheet.

How do I remove a fill without deleting the cell contents?
Set Interior.ColorIndex to xlColorIndexNone. This clears the fill formatting while leaving the cell’s value intact. It does not clear other formatting such as borders or font settings.

Why does VBA return a different color from the one I see?
The visible fill may be produced by conditional formatting, while Interior.Color refers to direct formatting. In a macro, read DisplayFormat.Interior.Color when you need the displayed result. A theme color or fill pattern can also affect how a cell appears.

Can I run an Excel VBA color macro in a browser?
No. Excel for the web does not run VBA macros. Open the workbook in the desktop Excel app for Windows or Mac to use VBA, and retain the workbook in an appropriate macro-enabled format if the code needs to be saved.

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.