(Solved) – Vba compare date columns in Loop

(solved)-–-vba-compare-date-columns-in-loop

How can I compare date columns? I have the the dates in a format ‘dd/mm/yyyy’ and the following code, however it just compares days, not months and years:

For j = 13 To lCol Step 2

 For i = 2 To lRow

         If Year(Cells(i, 10).Value) > Year(Cells(i, j).Value) Then Cells(i, j).Font.Color = vbRed
         If Month(Cells(i, 10).Value) > Month(Cells(i, j).Value) Then Cells(i, j).Font.Color = vbRed
         If Day(Cells(i, 10).Value) > Day(Cells(i, j).Value) Then Cells(i, j).Font.Color = vbRed
 Next i

Next j

Leave a Reply

Your email address will not be published. Required fields are marked *