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 post, you’ll learn how to Find Blank cells in excel so that you can remove or delete the blank cells form...
In this article, you’ll learn what is a Gauge Chart in Microsoft Excel. Also, you will learn how to add...
Microsoft Excel provides a shortcut for the users to move columns in excel using two different ways – using Shift...