Condition Formatting the every Row base on the row beside

darkdarkwt

New Member
Joined
Jun 9, 2015
Messages
3
The idea is to highlight the cell based on row beside
if the target date is less than 14 days from today then Cell F ( same row) will fill with orange colour
if less than 7 days then it will fill up with red colour
if more than 14 days it will be green in colour.

below is the code which i came out , nothing come out after i click run .
please help me >< and thank you very much .

Code:
Sub Alert()
Dim RowNum As Integer
RowNum = 5
Do While RowNum <= 255
    Range("F" & RowNum).FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=AND((D&RowNum-TODAY())<=7,(D&RowNum-TODAY())>=0)"
     Range("F" & RowNum).FormatConditions(Range("F" & RowNum).FormatConditions.Count).SetFirstPriority
    With Range("F" & RowNum).FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 255
        .TintAndShade = 0
    End With
     Range("F" & RowNum).FormatConditions(1).StopIfTrue = False
     Range("F" & RowNum).FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=(D&RowNum-TODAY())>14"
     Range("F" & RowNum).FormatConditions(Range("F" & RowNum).FormatConditions.Count).SetFirstPriority
    With Range("F" & RowNum).FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 5287936
        .TintAndShade = 0
    End With
     Range("F" & RowNum).FormatConditions(1).StopIfTrue = False
    
    Range("F" & RowNum).FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=AND((D&RowNum-TODAY())<=14,(D&RowNum-TODAY())>7)"
     Range("F" & RowNum).FormatConditions(Range("F" & RowNum).FormatConditions.Count).SetFirstPriority
    With Range("F" & RowNum).FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 49407
        .TintAndShade = 0
    End With
    Range("F" & RowNum).FormatConditions(1).StopIfTrue = False
    RowNum = RowNum + 1
    
Loop
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,214,808
Messages
6,121,684
Members
449,048
Latest member
81jamesacct

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