#### Rafael Alvares Tubero

##### New Member

- Joined
- Mar 18, 2011

- Messages
- 45

Hello everybody!

I would like to know why my function is not working. Can anybody help me, please?

Thanks

I would like to know why my function is not working. Can anybody help me, please?

Code:

```
Function interpolin(dia As Double, ByVal rangedia, ByVal rangevalor) As Double
If UBound(rangedia) <> UBound(rangevalor) Then
End Function
End If
If dia < rangedia(0) Then
interpolin = (dia - rangedia(0)) * ((rangevalor(1) - rangevalor(0)) / (rangedia(1) - rangedia(0))) + rangevalor(0)
End Function
End If
If dia > rangedia(UBound(rangedia)) Then
interpolin = (dia - rangedia(UBound(rangedia) - 1)) _
* ((rangevalor(UBound(rangevalor)) - rangevalor(UBound(rangevalor) - 1)) _
/ (rangedia(UBound(rangedia)) - rangedia(UBound(rangedia) - 1))) + rangevalor(UBound(rangevalor) - 1)
End Function
End If
For i = 0 To UBound(rangedia)
If dia >= rangedia(i) And dia <= rangedia(i + 1) Then
interpolin = (dia - rangedia(i)) * ((rangevalor(i + 1) - rangevalor(i)) / (rangedia(i + 1) - rangedia(i))) + rangevalor(i)
End Function
End If
Next
End Function
```

Thanks

Last edited by a moderator: