Finding Min of Values (dates)

D

dchristo

I need to find the lowest values of a set of dates, I tried using
MinOfList()
Function MinOfList(ParamArray varValues()) As Variant
Dim i As Integer 'Loop controller.
Dim varMin As Variant 'Smallest value found so far.

varMin = Null 'Initialize to null

For i = LBound(varValues) To UBound(varValues)
If IsNumeric(varValues(i)) Then
If varMin <= varValues(i) Then
'do nothing
Else
varMin = varValues(i)
End If
End If
Next

MinOfList = varMin
End Function

But nothing happens, can someone please direct me on how to accomplish this?

Thank you
 
J

John Nurick

The function is badly named: MinOfListOfNumbers() would be better.

In the present case the problem is caused by IsNumeric() excluding
dates. How about changing it to IsDate() and rename the function to
MinOfListOfDates
 
J

John Nurick

Initalizing varMin to Null doesn't help either!

I don't think that's a problem. If varMin is Null, the
If varMin <= varValues(i)
will always be False and the assignment
varMin = varValues(i)
will be made. Am I missing something?

 
D

Douglas J. Steele

Sorry, you're right. varMin will get a value assigned the first time, so it
doesn't matter after that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top