Change row color based on other cell values within a specific range

Q_cripple

New Member
Joined
Dec 16, 2022
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone,

I've been struggling to code VBA (I'm new to VBA). I can't use conditional formatting because it's an Excel being continuously enriched with new data.

The aim is to color the font within a specific range of columns (A:S):
1. in red if the cell in column A is dated to today.
2. no coloring (black) if 1 does not apply (= the date in column A is older than today).
3. In green if the cell in column R contains a date (this takes precedence over 1 and 2).

I started working on 1 only but it's proven too big a challenge to work on specific range. The below is how far I got. This works for 1 but trying to add If for #2, I get errors (next without for, stuff like that). Can someone help out with a code?

Thanks in advance for any help you can provide.
PS: I tried more complex iterations with Dims but I just ended up getting lost and settled for this simple option, which took me 4 hours anyways...

Sub Format_cells()

Dim Cell As Range

Worksheets("Sheet1").Range("A2:S2").Select
Range(Selection, Selection.End(xlDown)).Select

For Each Cell In Selection

If Cell.Value = Worksheets("Sheet2").Range("G3") Then 'This is to get today's date from another sheet.
Cell.EntireRow.Font.ColorIndex = 3

End If

Next

End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Btw I tried using:

ElseIf Cell.Value < Worksheets("Sheet2").Range("G3") Then
Cell.EntireRow.Font.ColorIndex = 0

However it just overwrites the first part.
 
Upvote 0

Forum statistics

Threads
1,214,632
Messages
6,120,652
Members
448,975
Latest member
sweeberry

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