Advertisement
vityata

checkWithDates

Feb 22nd, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. Public Sub TestMe()
  4.    
  5.     ThisWorkbook.Date1904 = True            'this is dangerous!
  6.    Cells.Clear
  7.     Dim cnt     As Long
  8.    
  9.     For cnt = 3 To 20
  10.         Cells(1, cnt) = DateAdd("M", cnt, DateSerial(2016, 1, 1))
  11.         Cells(1, cnt).NumberFormat = "MMM-YY"
  12.     Next cnt
  13.    
  14.     Dim someDates(2)    As Date
  15.     someDates(0) = DateSerial(2016, 1, 1)   'exists
  16.    someDates(1) = DateSerial(2012, 1, 1)   'does not exist
  17.    someDates(2) = 1                        '31.12.1899
  18.    
  19.     Dim foundRange      As Range
  20.     For cnt = LBound(someDates) To UBound(someDates)
  21.         Set foundRange = Rows(1).Find(someDates(cnt))
  22.         If Not foundRange Is Nothing Then
  23.             foundRange.Interior.Color = vbRed
  24.         End If
  25.     Next cnt
  26.    
  27.     ThisWorkbook.Date1904 = False
  28.    
  29. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement