Change cell background color using VBA

Important notice for users of Office 2003    To continue receiving security updates for Office, make sure you're running Office 2003 Service Pack 3 (SP3). The support for Office 2003 ends April 8, 2014. If you’re running Office 2003 after support ends, to receive all important security updates for Office, you need to upgrade to a later version such as Office 365 or Office 2013. For more information, see Support is ending for Office 2003.

Applies to
Microsoft Office Excel 2003

Mr. Excel logo This article was adapted from MrExcel.com. Visit the MrExcel.com Web site for more tips and information.

How can you modify the background color of a cell by using Visual Basic for Applications (VBA)?

You have to use the Interior property of the cell, and then:

  • You can use ColorIndex (to use one of the 56 "preset" colors in Excel):
ActiveCell.Interior.ColorIndex = 36
  • Or you can use Color:
Range("A1:A6").Interior.Color = RGB(200,160,35)
 
 
Applies to:
Excel 2003