Changing background colors in Excel VBA is easy. Use the Interior property to return an Interior object. Then use the ColorIndex property of the Interior object to set the background color of a cell.
Place three command buttons on your worksheet and add the following code lines:
1. The code line below sets the background color of cell A1 to light blue.
2. The following code line sets the background color of cell A1 to ‘No Fill’.
3. If you want to know the ColorIndex number of a color, simply ask Excel VBA.
Select cell A1 and click the command button on the sheet:
4. The ColorIndex property gives access to a color palette of 56 colors.
Note: download the Excel file to see how we created this color palette.
5. If you can’t find the specific color you are looking for, use the Color property and the RGB function.
Explanation: RGB stands for Red, Green and Blue. These are the three primary colors. Each component can take on a value from 0 to 255. With this function you can make every color. RGB(255,0,0) gives the pure Red color (ColorIndex = 3 produces the exact same result).