title: Using DateSerial function with loop and If statement
body: <p>I am trying to write a code that will hide all past dates and the blank rows in a year long database. The issue with the code below is that the code sees the dates at math problems to solve, i.e <code>? 1/1/2016 &lt; 1/14/2016 = false</code> because of division. I had a suggestion to use the DateSerial function but I am not sure how to use it within a loop or the if statement.</p>
  
  <p>Code As is: </p>
  
  <pre><code> Sub Hide_Dates()
   Dim This_Year As Range
   Dim CD As Date
   Dim SD As Date
  
   Application.ScreenUpdating = False
   Application.Calculation = xlCalculationManual
  
   Set This_Year = Range("A5:A3000")
   This_Year.EntireRow.Hidden = False
   i = 5
  'CD = Format(Date, "dddd, mmmm dd,yyyy")
   CD = Date
  
   Do Until Cells(i, 1) = CD
  
   SD = Cells(i, 1).Value
   Debug.Print i
   Debug.Print SD
   Debug.Print CD
   If SD &lt; CD Or SD = "" Then
       Rows(i).EntireRow.Hidden = True
   End If
  
   i = i + 1
   Loop
  
   Application.ScreenUpdating = True
   Application.Calculation = xlCalculationAutomatic
  
   End Sub
  </code></pre>
  
  <p>Code with DateSerial attempt:</p>
  
  <pre><code>  Sub Hide_Dates()
    Dim This_Year As Range
    Dim CD As Date
    Dim SD As Date
  
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
  
    Set This_Year = Range("A5:A3000")
    This_Year.EntireRow.Hidden = False
  
   'Starts rows down
    i = 5
  
   'Current date
   'CD = Format(Date, "dddd, mmmm dd,yyyy")
   CD = DateSerial(Today.Year, Today.Month, Today.Day)
  
   Do Until Cells(i, 1) = CD
  
  'SD = Selected Date in the loop
   SD = Cells(i, 1).Value 'Not sure how to DateSerial this!!!!
   Debug.Print i
   Debug.Print SD
   Debug.Print CD
   'Hides past days
   If SD &lt; CD Or SD = "" Then
      Rows(i).EntireRow.Hidden = True
   End If
  
   i = i + 1
   Loop
  
   Application.ScreenUpdating = True
   Application.Calculation = xlCalculationAutomatic
  
   End Sub
  </code></pre>