Question

i am trying to find out the maximum value from the array ---> FinishDateArray()
However, the MaxDate value is coming out to be 0 each time. Any idea what could be wrong in this? The array contains dates and I wish to find highest of them.

The below for loop shows that the array does contain all values. But running the inbuilt Max command doesnt give the maximum date. Please help.

Below is the code:

For i = 0 To UBound(FinishDateArray)  
    MsgBox i & " Date: " & FinishDateArray(i)  
Next i  
MaxDate = WorksheetFunction.Max(FinishDateArray)

MsgBox "Max Date: " & MaxDate
Was it helpful?

Solution

I also had the same problem. So I searched the web for the answer, but I haven't found it yet. Maybe it's MS's mistake, I think. Instead, I figured out a solution. Here it is.

ReDim CLngArray(UBound(FinishDateArray))

For i = 0 To UBound(FinishDateArray)  
CLngArray(i) = CLng(FinishDateArray(i))  
Next i  
MaxDate = CDate(WorksheetFunction.Max(CLngArray))
MsgBox "Max Date: " & MaxDate

OTHER TIPS

For me what solved the problem was using the function WorksheetFunction.Max(RangeDate), where RangeDate is the range where the dates are positioned. So instead of giving the values you could give the ranges and that works fine!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top