문제

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