Tuesday, March 30, 2010

How to compare dates in Excel Macro

Well this is quite simple.... if you have a cell value as 3/28/10 (m/dd/yy)... which is 3rd March 2010 and you need to compare this with the data 28/03/2010 ... which is in dd/mm/yyyy format

All you need to do is to convert the data in the required format to match

compare_Dt = Format(DateSerial(Yr, Mo, Dt), "mm/dd/yyyy")

For j = rng1 to rng2
      Source= Format(Cells(3, j).Value, "mm/dd/yyyy")
      If Source = compare_Dt Then
         your code when the date matches
         Exit For
     End If
Next

No comments:

Post a Comment