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
有帮助吗?

解决方案

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

其他提示

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!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top