Conditional formation by cell colour?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,
So I have a grid, (Range B4:Z24) in each cell is a name

I also have a legend of colours (Sheets("Control").range("L3:L10") for each Name

Now I need to fill each cell with the fill colour of the name in that cell.
Dont mind if its a macro or conditional formating, but any ideas would be great thanks
Tony
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
There is no built-in worksheet functionality to determine the color of a cell, so you can't do it with a single conditional formatting rule. You have two options:

1. Create 8 conditional formatting rules, one for each color you have in your legend at L3:L10. Eight rules isn't too bad. You will have to update the rules any time the colors in the legend change.
2. Use VBA. If you use VBA the colors will be permanent and any time your data changes you will have to re-run the VBA. However, you do not have to change code if the colors in the legend changer. You did not give the name of the sheet containing the names so update the following code where Grid is the name and change it to the actual name.

VBA Code:
Public Sub ColorCode()

   Dim Cell As Range
   Dim Found As Range
   
   For Each Cell In Worksheets("Grid").Range("A1:E12")
   
      Set Found = Sheets("Control").Range("L3:L10").Find(What:=Cell.Value, lookat:=xlWhole)

      If Found Is Nothing Then
         MsgBox """" & Cell.Value & """ in cell " & Cell.Address & " not found in Legend."
      Else
         Cell.Interior.Color = Found.Interior.Color
      End If
   
   Next Cell

End Sub
 
Upvote 0
6StringJazzer, this is perfect, no problem having it rerun everytime data changes :)
Thanks
Tony
 
Upvote 0
Very important: I left in the range I used to test. You need to update to your actual range:

Rich (BB code):
   For Each Cell In Worksheets("Grid").Range("B4:Z24")
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,497
Members
448,967
Latest member
visheshkotha

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top