Date difference with loop ?

Zaharoff

New Member
Joined
Jul 25, 2006
Messages
9
Hi,
I have a table to organise document receiption. I have 2 column : the first it the expected date, the second it the reveived date.
I made a macro to highlight in red the first column when dates are late if nothing received.
Now i want to highlight in an other color the 2nd and the 1st column when the document reveived is late. Means i want the difference between these 2 dates, and then if the difference is >0 or <0 (depends of the sign) i want to highlight the 2 cells.

I have this for my first column, that works.

If Not Range("G" & k) = "" Then
Range("G" & k).Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=G" & k & "<TODAY()"

Selection.FormatConditions(1).Interior.ColorIndex = 3
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=IF(AND(G" & k & "<=5+TODAY()),(G" & k & ">TODAY()))"
Selection.FormatConditions(2).Interior.ColorIndex = 36
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=G" & k & "=TODAY()"
Selection.FormatConditions(3).Interior.ColorIndex = 20
End If

Next k


I tried something like this for the 2nd column, but that does not work.


If Not Range("H" & k) = "" Then
Range("H" & k).Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=H" & k & "<G"

Selection.FormatConditions(1).Interior.ColorIndex = 36
End If
Next k



Thanks for your help
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,222,900
Messages
6,168,926
Members
452,227
Latest member
sam1121

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