alektherussian
New Member
- Joined
- Sep 12, 2014
- Messages
- 8
Hi guys,
I'm trying to use a custom function that we're supposed to use at work, but the problem is it doesn't accept array as argument (so I can't do ctrl+shift+enter).
This is a custom percentile function:
Could you help me rewrite it so that it accepts array as argument?
Your help is greatly appreciated!
I'm trying to use a custom function that we're supposed to use at work, but the problem is it doesn't accept array as argument (so I can't do ctrl+shift+enter).
This is a custom percentile function:
Code:
Function LPercentile(rArray As Variant, p1, Optional AtPosition As Boolean) As Variant
Dim tArray() As Variant
nvals = rArray.Cells.Count
n = 0
For Each nval In rArray.Cells
If Application.WorksheetFunction.IsNumber(nval) = True And nval <> "" Then
n = n + 1
ReDim Preserve tArray(n)
tArray(n) = Val(nval)
End If
Next nval
If IsMissing(AtPosition) Then
AtPosition = False
End If
If p1 <= 1 Then
p1 = p1 * 100
End If
p2 = 100
Ordinal = ((p1 * (n + 1)) / p2)
If Not AtPosition Then
Ordinal = Ordinal + kStart
End If
k = Int(Ordinal)
r = Ordinal - k
n = n + kStart
If Not AtPosition Then
a = Application.Large(tArray, n - (k - 1))
b = Application.Large(tArray, n - k)
Else
a = tArray(k)
b = tArray(k + 1)
End If
LPercentile = a + ((b - a) * r)
End Function
Could you help me rewrite it so that it accepts array as argument?
Your help is greatly appreciated!