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

Office Tab Enable Tabbed Editing and Browsing in Office, and Make Your Work Much Easier...
Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%
  • Reuse Anything: Add the most used or complex formulas, charts and anything else to your favorites, and quickly reuse them in the future.
  • More than 20 text features: Extract Number from Text String; Extract or Remove Part of Texts; Convert Numbers and Currencies to English Words.
  • Merge Tools: Multiple Workbooks and Sheets into One; Merge Multiple Cells/Rows/Columns Without Losing Data; Merge Duplicate Rows and Sum.
  • Split Tools: Split Data into Multiple Sheets Based on Value; One Workbook to Multiple Excel, PDF or CSV Files; One Column to Multiple Columns.
  • Paste Skipping Hidden/Filtered Rows; Count And Sum by Background Color; Send Personalized Emails to Multiple Recipients in Bulk.
  • Super Filter: Create advanced filter schemes and apply to any sheets; Sort by week, day, frequency and more; Filter by bold, formulas, comment...
  • More than 300 powerful features; Works with Office 2007-2019 and 365; Supports all languages; Easy deploying in your enterprise or organization.

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:


Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
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.
    Sam Morris · 2 months ago
    I've attached a screen shot of the file Im working on - I don't seem to be able to upload a .xlsm file? In this file I have used the original VBA from this thread and can now match the conditionally formatted colour of cell A10 in D10. How can I get this to work on a range of cells? I would like to get the colour of the range of cells A10:A200 to transfer over to D10:D200. Can anyone help please? There is a drop down list in use in the A column but once we have placed an order we need to be able to over type the purchase order number. The items in the list are all set to conditionally format to a colour (eg ORDER OK turns cell green, CLIENT TBC turns cell yellow) but the colour goes blank once the PO has been put in.
  • To post as a guest, your comment is unpublished.
    Sam Morris · 2 months ago
    Wow - this is great. I hope you can help me adapt your script to my needs. I need to make cells D10:D200 match the conditionally formatted colour of cells A10:A200 - can you help me to get this working please. The cells are all in the same worksheet.
  • To post as a guest, your comment is unpublished.
    Tony · 10 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 · 10 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 · 1 years 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 · 1 years 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 · 9 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 · 1 years 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 · 1 years ago
      I have the same problem. Works on cells without conditional formatting but doesn't with those that do