title: How to find max and min date in a range of another sheet?
body: <p>I am writing VBA code to find the minimum and maximum dates in a Range. When I execute it, I get an error:</p>
  
  <blockquote>
    <p>Run-time error '1004': Application-defined or object-oriented error. </p>
  </blockquote>
  
  <p>Below is my code:</p>
  
  <pre><code>Sub GenerateSheet()
  
      Dim i, r, numAssignments As Integer
      Dim ssrRng, DestRange As Range
      Dim StartDate, EndDate, d As Date
  
      numAssignments = Sheets("Data").Range("A1048576").End(xlUp).Row - 1
      Sheets("Schedule").Select
  
      EndDate = WorksheetFunction.Max(Sheets("Data").Range(Cells(2, 8), Cells(numAssignments, 8)))
      StartDate = WorksheetFunction.Min(Sheets("Data").Range(Cells(2, 5), Cells(numAssignments, 5)))
  
  End Sub
  </code></pre>
  
  <p>Here, Data Sheet has 8 columns, Column 5 and 8 are dates</p>