Set Cell Color based on Another Cell Color

,

This post will guide you how to set the color of a cell based on another cell color in excel. How do I change the color of cells same as another cell in excel. how to set a cell color equal to another with VBA code in excel.

Set Cell Color based on Another Cell Color


Assuming that you have one cell (B1) set the color as red, and you want to set the color of Cell D1 based on the Cell B1, how to achieve it. To change cell color based on another cell color in excel, you can create an excel VBA macro to achieve the result. Just do the following steps:

#1 right click on the sheet tab in your current worksheet, and select View Code from the popup menu list.

set cell color1

#2 then the “Visual Basic Editor” window will appear.

#3 paste the below VBA code into the code window. Then clicking “Save” button.

set cell color2

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Me.Range("D1").Interior.Color = Me.Range("B1").Interior.Color
End Sub

#4 Lets see the result:

set cell color3

You will see that the color of Cell D1 will be filled with the color of the cell B1. and if you change the color of cell B1, and the color of Cell D1 will be changed automatically based on the Cell B1 color.

 

 

Leave a Reply