Function

Joined
Mar 18, 2011
Messages
45
Hello everybody!

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:

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Perhaps

Rich (BB code):
Function interpolin(dia As Double, ByVal rangedia, ByVal rangevalor) As Double

If UBound(rangedia) <> UBound(rangevalor) Then
Exit Function

End If

If dia < rangedia(0) Then

interpolin = (dia - rangedia(0)) * ((rangevalor(1) - rangevalor(0)) / (rangedia(1) - rangedia(0))) + rangevalor(0)
Exit 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)
Exit 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)
Exit Function

End If

Next
End Function
 
Upvote 0
I have already changed. It doesn't work anyway.

I really need a hand here. When I try to run the function it is give #VALUE! as output. I have tried to change how I declared the variables and it still doesn't work. I am lost.
Code:
Function interpolin(dia As Double, rangedia() As Variant, rangevalor() As Variant) As Double

If UBound(rangedia) <> UBound(rangevalor) Then
    Exit Function
    
End If

If dia < rangedia(0) Then
    
    interpolin = (dia - rangedia(0)) * ((rangevalor(1) - rangevalor(0)) / (rangedia(1) - rangedia(0))) + rangevalor(0)
    Exit 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)
    Exit 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)
        Exit Function
        
    End If
    
Next
End Function
 
Last edited by a moderator:
Upvote 0
I have tried to put a breakpoint but it is not running through the code. It stops at the first line where I announce the function.

Also I am calling the function like this:

[TABLE="width: 728"]
<TBODY>[TR]
[TD]4</SPAN>[/TD]
[TD]10</SPAN>[/TD]
[TD][/TD]
[TD]3</SPAN>[/TD]
[TD]=interpolin(E3;B3:B6;C3:C6)</SPAN>[/TD]
[/TR]
[TR]
[TD]6</SPAN>[/TD]
[TD]50</SPAN>[/TD]
[TD][/TD]
[TD]4</SPAN>[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]8</SPAN>[/TD]
[TD]70</SPAN>[/TD]
[TD][/TD]
[TD]5</SPAN>[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]10</SPAN>[/TD]
[TD]100</SPAN>[/TD]
[TD][/TD]
[TD]6</SPAN>[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]7</SPAN>[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]8</SPAN>[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]9</SPAN>[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]10</SPAN>[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]11</SPAN>[/TD]
[TD][/TD]
[/TR]
</TBODY><COLGROUP><COL span=4><COL></COLGROUP>[/TABLE]
 
Upvote 0

Forum statistics

Threads
1,226,453
Messages
6,191,137
Members
453,642
Latest member
jefals

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top