注:1)我不想使用Application.Worksheetfunction.Min; 2)我想拒絕不是vbDouble的數組元素; 3)我不知道提前很多元素是如何傳遞的數組中傳遞數組到函數返回最小值在Array
Public Function getArrayMin(ByRef passedArray() As Double) As Double
'return min of valid numbers in an array
Dim element As Variant
Dim i As Integer
getArrayMin = 1E+25
i = 0
For Each element In passedArray
If VarType(element) = vbDouble Then
i = i + 1
If element < passedArray(i) Then
getArrayMin = passedArray(i)
End If
End If
Next
End Function
JNevill的編輯的版本,仍然不能正常工作:
Function getArrayMin(passedArray() As Double) As Double
Dim minVal As Double
Dim element As Variant
minVal = 1E+25
For Each element In passedArray
If element < minVal Or element = passedArray(0) Then
minVal = element
End If
Next element
getArrayMin = minVal
End Function
你沒有任何回報。另外,雖然'cell'在技術上很好,但可以嘗試像'element'這樣的東西嗎? – findwindow