Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to set cell color equal to another cell color in Excel?

If you want to match a cell color to another, a method in this article can help you.

Set cell color equal to another cell color with VBA code


Set cell color equal to another cell color with VBA code


The below VBA method can help you set a cell color equal to another in Excel. Please do as follows.

1. In the worksheet you need to match the color of two cells, please right click the sheet tab, and then click View Code from the right-clicking menu. See screenshot:

2. In the opening Microsoft Visual Basic for Applications window, you need to copy and paste VBA code into the Code window.

VBA code: Set cell color equal to another cell color

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

Note: In the code, A1 is the cell contains the fill color you will match to C1. Please change them based on your needs.

Then the cell C1 is filled with the same color of cell A1 as below screenshot shown.

From now on, when fill color in A1 is changed, C1 will be matched with the same color automatically.


Related articles:


Recommended Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 71%, and Help You To Stand Out From Crowd!

Would you like to complete your daily work quickly and perfectly? Kutools For Excel brings 300+ cool and powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) for 1500+ work scenarios, helps you solve 82% Excel problems.

  •  Deal with all complicated tasks in seconds, help to enhance your work ability, get success from the fierce competition, and never worry about being fired.
  •  Save a lot of work time, leave much time for you to love and care the family and enjoy a comfortable life now.
  •  Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands, and give you a healthy body.
  •  Become an Excel expert in 3 minutes, and get admiring glance from your colleagues or friends.
  •  No longer need to remember any painful formulas and VBA codes, have a relaxing and pleasant mind, give you a thrill you've never had before.
  •  Spend only $39, but worth than $4000 training of others. Being used by 110,000 elites and 300+ well-known companies.
  •  60-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years. Buy once, use forever.
  •  Change the way you work now, and give you a better life immediately!

Office Tab Brings Efficient And Handy Tabs to Office (include Excel), Just Like Chrome, Firefox, And New IE

  • Increases your productivity by 50% when viewing and editing multiple documents.
  • Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
  • Open and create documents in new tabs of same window, rather than in new windows.
  • Help you work faster and easily stand out from the crowd! One second to switch between dozens of open documents!
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Tony · 3 months ago
    As Chris I am interested in copying the background color from another worksheet?
  • To post as a guest, your comment is unpublished.
    Chris · 3 months ago
    I found your code to 'set cell color to equal to another cell color" and it works when I am using it on the same worksheet ( ex from cell A1 to cell A2). I am wondering if there is a way to have this same functionality from another worksheet (ex to copy cell color from sheet1!A1 to sheet2!A1? Any help you could offer would be appreciated!
  • To post as a guest, your comment is unpublished.
    Zack · 6 months ago
    This is a good start to what I am looking to do. But I am looking for something a bit more complicated

    How could I adapt this to apply to multiple rows and a range. For instance I have a header column in Column B, I want cells from G to CS to match the colour of the header row but only is they have something in them ie the letter x. I know I can write an IF and THEN statement but how would I apply it to multiple Rows without writing a code for each row.
  • To post as a guest, your comment is unpublished.
    yesser · 1 years ago
    hi , how to apply the same VBA but on a range of cells for example :

    i want to have the same color of range (C8:X8) to be apply on the range (S16:AL16) one by one in the same order (S16 get the color of C16 , T16 get the color of D8 ....etc)
    • To post as a guest, your comment is unpublished.
      crystal · 9 months ago
      Good day,

      The below VBA code can help you solving the problem. Thanks for your comment.

      Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      Dim xSRg, xDRg, xISRg, xIDRg As Range
      Dim xFNum As Long
      On Error Resume Next
      Set xSRg = Range("C8:X8")
      Set xDRg = Range("S16:AL16")
      For xFNum = 1 To xSRg.count
      Set xISRg = xSRg.Item(xFNum)
      Set xIDRg = xDRg.Item(xFNum)
      xIDRg.Interior.Color = xISRg.Interior.Color
      Next xFNum
      End Sub
      • To post as a guest, your comment is unpublished.
        Shaun Symmonds · 3 months ago
        Hi

        I am trying to do similar, but I have two spreadsheets (files). Spreadsheet 1 is the Master where the data is manually updated and file (spreadsheet 2) is equalling the data in the same cell as spreadsheet 1. When I open spreadsheet 2, I get a prompt to refresh with spreadsheet 1 no promlems, but if the colour of the cell is changed in spreadsheet 1 it does not update in spreadsheet 2, neither does 'strike-trough' of fonts..help please?
  • To post as a guest, your comment is unpublished.
    JJ · 1 years ago
    Hi, the cell being referenced for colour changes colour based on conditional formatting. The above doesn't seem to work with that and the destination cells are staying blank. How can this be corrected? Thanks
    • To post as a guest, your comment is unpublished.
      LP · 7 months ago
      If you have Excel 2010 or later you can use the DisplayFormat function to return the color of a conditionally formatted cell. See below:

      Private Sub Worksheet_SelectionChange(ByVal Target As Range)
      Me.Range("C1").Interior.Color = Me.Range("A1").DisplayFormat.Interior.Color
      End Sub
    • To post as a guest, your comment is unpublished.
      Marty · 9 months ago
      I have the same problem. Works on cells without conditional formatting but doesn't with those that do