title: With the code below I receive the error Variable not defined
body: <p>Columns A, D and E are date and time.</p>
  
  <p>I am trying to find out how many times the date in Column A falls between the start dates and end dates.</p>
  
  <p>Column A may vary between 30 and 60 days while the start and end dates run to thousands.</p>
  
  <p>Two questions:</p>
  
  <ol>
  <li>Why am I receiving error Variable Not defined with the code below?</li>
  <li>If cell A2 is date and time 24Feb17 12H00 then what formula do I put in cell A3 so that it reads 25Feb17 12H00 and so on?</li>
  </ol>
  
  <p>Code:</p>
  
  <pre><code>Option Explicit
  Sub DaysCount()
      Dim endRow As Long
      Dim LastRow As Long
      Dim ICount As Long
      Dim Day() As Variant
      Dim StartDate() As Variant
      Dim EndDate() As Variant
      ICount = 0
      With ThisWorkbook.Worksheets("sheet1")
          LastRow = .Range("A" &amp; .Rows.count).End(xlUp).Row
          endRow = .Range("D" &amp; .Rows.count).End(xlUp).Row
          Day = Sheet1.Range("A2:A" &amp; LastRow)
          StartDate = Sheet1.Range("D2:D" &amp; endRow)
          EndDate = Sheet1.Range("E2:E" &amp; endRow)
  
          For i = LBound(StartDate) To UBound(StartDate)
              For J = LBound(Day) To UBound(Day)
                  If Day(J, 1) &gt;= StartDate(i, 1) And Day(J, 1) &lt;= EndDate(i, 1) Then
                      ICount = ICount + 1
                  Else
  
                  End If
                  Sheet1.Range("B" &amp; J).Value = ICount
              Next i
              ICount = 0
          Next J
      End With
  End Sub
  </code></pre>