I am writing VBA code to find the minimum and maximum dates in a Range. When I execute it, I get an error:
Run-time error \'1004\': Application-define
You are telling range that its parent is Sheets("Data") but not cells. For all intents and purposes you wanted a range from Data!E2:Schedule!E99.
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
with Sheets("Data")
EndDate = WorksheetFunction.Max(.Range(.Cells(2, 8), .Cells(numAssignments, 8)))
StartDate = WorksheetFunction.Min(.Range(.Cells(2, 5), .Cells(numAssignments, 5)))
end with
End Sub
Using the With Sheets("Data") tells everything inside that block that is prefaced with a period (aka . or full stop) that its parent is Sheets("Data").