I have a problem with your function. You want to find the minimum value in the array and its position? If that is the case, I don't think it works. Firstly, you are sorting the non-null values, which removes any indication of where they were in the array, and secondly, you are asking for a value in a specific position in the sorted array (intPosition), and unless intPosition=0, you are not getting the minimum.
You don't need the sort - you can scan the array and get the minimum and the position on one pass.
Something like this (untested):
Code:
Function NthMinimum(intPosition As Integer, ParamArray FieldArray() As Variant) As Variant
Dim varTempValue As Variant, intArrayValues As Integer
Dim I As Integer
Dim CurrentMinimum as Variant, CurrentPosition as variant
intArrayValues = 0
'
' Initialize CurrentMinimum to some "large" value, more than the largest possible value in the array
'
CurrentMinimum = 99999
CurrentPosition = 9999
For i = 0 to ubound(fieldarray)
'
' If this array member is smaller that the current values, reset the values
'
if not IsNull(FieldArray(I)) then
if fieldarray(i) < currentminimum then
currentminimum = fieldarray(i)
currentposition = i
endif
endif
next i
'
' At this point, the CurrentMinimum will be the minimum value in the array,
' and CurrentPosition will be where it was found (0 based)
'
nthMinimum = CurrentMinimum
intPosition = CurrentPosition
End Function
This function does what you say you want it to do, which is to find the minimum value in the array, and its position.
I don't know what you were doing with intPosition, so I used it to return the position of the minimum value.
The function returns the position of the first occurance of duplicate minimum values; if you want to return the second (or last) one, use if fieldarray(i) <= currentminimum then
I hope this helps.
John