How to Change Background Colors of Cells in Excel VBA?

In this article, you will learn how to change background colors of cells in Excel VBA and apply them in your Excel spreadsheet.

Change Background Colors of Cells in Excel VBA

You can 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.

To Change Background Colors in Excel VBA, follow the below steps

You can use both cell and range methods to change the background.

Let’s see the Range method.

Place three command buttons on your worksheet

This code will change the background color of cell A1 to Dark blue.

Code:

Range("A1").Interior.ColorIndex = 57
How to Change Background Colors of Cells in Excel VBA?

This code will change the background color of cell A1 to ‘No Fill’.

Code:

Range("A1").Interior.ColorIndex = 0
How to Change Background Colors of Cells in Excel VBA?

To know the color index

Code:

MsgBox Selection.Interior.ColorIndex
How to Change Background Colors of Cells in Excel VBA?

Select cell A1 and click the command button on the sheet.

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

In this article, you will learn about the SKEW.P function, the formula syntax and usage of the function in Microsoft...
In this article, you will learn about the SKEW function, the formula syntax and usage of the function in Microsoft...
In this article, you will learn about the RANK.EQ function, the formula syntax and usage of the function in Microsoft...
  • Excel
  • November 23, 2021