title: How can I compare two dates in Excel VBA?
body: <p>I'm working on a school project to compare if date1 is equal to date2 - 1 (date1 is one day earlier than date2).</p>
  
  <p>date2 is located one cell below date1. This is will be placed in an if/else statement where the comparison will return a Boolean.</p>
  
  <p>This is the code that I am working on,</p>
  
  <pre><code>Sub someLoop()
  
  Dim night As Long
  night = 1
  
  Dim c As Long
  
  Dim max_rows As Long
  
  max_rows = UsedRange.Rows.Count
  
  For c = 2 To max_rows
      Range("A" &amp; c).Select
      If ActiveCell.Value = ActiveCell.Offset(1, 0).Value2 - 1 Then
          night = night + 1
      Else
          ActiveCell.Offset(0, 2).SetValue = night
          night = 1
      End If
  
  Next c
  
  End Sub
  </code></pre>