Man, man, man ... du machst es aber auch aufregender als es eigentlich ist. 😎
Option Explicit
Public Function QuantileFind(ByVal q As Double) As Variant
Dim i&, j&, m&
With Worksheets("Tabelle1")
With .Range("A2", .Cells(.Rows.Count, "A").End(xlUp))
'Funktion verlassen,
' falls wir oberhalb von A2 gelandet sind
If .Row < 2 Then
QuantileFind = Empty
Exit Function
End If
i = 1
j = .Count
Do While i < j
m = (i + j) \ 2
If q > .Cells(m, 1).Value Then
j = m - 1
ElseIf q < .Cells(m, 1).Value Then
i = m + 1
Else
QuantileFind = .Cells(m, 1).Offset(0, 1).Value
Exit Function
End If
Loop
QuantileFind = .Cells(WorksheetFunction.Max(i, j)).Offset(0, 1).Value
End With
End With
End Function
|