Forum Discussion
Daniel Cook
Aug 24, 2017Copper Contributor
How do I make excel change the colour of a cell depending on a different cells date?
Hi, How do I make excel change the colour of a cell depending on a different cells date? Turn A2 red if - E2 cell is smaller than todays date Turn A2 yellow with red outline if - E2 ce...
- Nov 21, 2022
Let's say you want to highlight a row if column F contains "Closed".
Use the formula
=$F2="Closed"
If you want something different, please provide more detailed information.
HansVogelaar
Oct 04, 2023MVP
Have the names on Sheet1 been colored manually or by a conditional formatting rule?
Scottsgt739
Oct 04, 2023Copper Contributor
They have been colored manually.
- Scottsgt739Oct 05, 2023Copper Contributor
I had a feeling it was not a simple answer. I greatly appreciate the help. I will try out the macro in the Visual Basic Editor.
- HansVogelaarOct 04, 2023MVP
Excel does not have a built-in way to do this. This will require VBA code.
Copy the following macro into a module in the Visual Basic Editor:
Sub ColorCells() Const shn1 = "Sheet1" ' Name of first sheet Const shn2 = "Sheet2" ' Name of second sheet Const col1 = "A" ' Column on first sheet Const col2 = "A" ' Column on second sheet Dim wsh1 As Worksheet ' First sheet Dim wsh2 As Worksheet ' Second sheet Dim rng1 As Range ' Cell on first sheet Dim rng2 As Range ' Cell on second sheet Application.ScreenUpdating = False Set wsh1 = Worksheets(shn1) Set wsh2 = Worksheets(shn2) wsh2.Columns(col2).Interior.ColorIndex = xlColorIndexNone For Each rng2 In Intersect(wsh2.Columns(col2), wsh2.UsedRange) Set rng1 = wsh1.Columns(col1).Find(What:=rng2.Value, LookAt:=xlWhole) If Not rng1 Is Nothing Then If rng1.Interior.ColorIndex <> xlColorIndexNone Then rng2.Interior.Color = rng1.Interior.Color End If End If Next rng2 Application.ScreenUpdating = True End SubChange the constants at the beginning of the macro as needed.
Run the macro whenever you want to update the colors on the second sheet.