Finding Min of Values (dates)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
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?

 
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

Similar Threads

Using GetRows 4
Print list box 1
Multi Select For Query 2
Mid range 2
Calling Functions 2
Can't understand use of variable in this code 3
Hide Columns 3
[MEWBIE} help with Null 3

Back
Top