Hello,

I am trying to get this VBA code to pull the second minimum value within my data while ignoring NULLs. It seems to work on some rows, but not on others. I was wondering if anyone knows what I am doing wrong within the VBA and hopefully help me out!

Function Minimum(ParamArray FieldArray() As Variant)

Dim I As Integer
Dim currentVal As Variant
Dim secondVal As Variant

currentVal = FieldArray(0)
secondVal = FieldArray(0)

For I = 1 To UBound(FieldArray)
If IsNull(currentVal) Then
currentVal = FieldArray(I)
ElseIf FieldArray(I) < currentVal Then
currentVal = FieldArray(I)
' Finds Second Minimum
ElseIf secondVal > currentVal And FieldArray(I) < secondVal Then
secondVal = FieldArray(I)
End If
Next I
Minimum = secondVal

End Function


Thanks in advance!