You don't need to set the object if you use selection:
Sub MinMaxDiff(): Dim StartTime As Date, StopTime As Date, Duration As Date
StartTime = Application.WorksheetFunction.MIN(Selection)
StopTime = Application.WorksheetFunction.MAX(Selection)
Duration = StopTime - StartTime
MsgBox Duration 'Range("A19")=Duration
End Sub
But wouldn't you rather write the duration on the spreadsheet?
Here's a function and a sub to call it:
Function Duration(R As Range) As Date
Dim Startime As Date, Stoptime As Date
Startime = Application.WorksheetFunction.MIN(R)
Stoptime = Application.WorksheetFunction.MAX(R)
Duration = Stoptime - Startime: End Function
Sub PostElapsed()
Range("A19") = Duration(Selection)
End Sub
Bookmarks