Dear All,

I'm new here, and new to Visual Basic, (but having a background in C and C++).
Sorry if my question is foolish, but I'm really puzzled by the problem I'm facing now.

I'm trying to write a simple user defined function, "calctemp(sensor, resistance As Double) As Double" below, which calculates a polynomial to the 6th degree
It should take the 7 coefficients of this polynomial (K_1 ... K_7) from cells in the same row as input cell "sensor" (with offset +1, +2... +7 to the right from that input cell).
And "resistance" is the variable taken with double precision, as the second input.

I wrote the code below. And it worked nicely, with the desired precision.
But, if I input resistance = 2774.0
it gives #VALUE! error. Regardless from the polynomial coefficients! Regardless from anything else, seemingly, except for the power of the polynomial.
This error occurs at power 5, and present above.
I don't know what's so special about this number 2774.0, already 2774.000001 gives a numerically correct result. Other round numbers (3300.0, whatever) work too, and I did not find other input values failing so far.

Am I doing something incorrect in the code? I'm not sure my usage of "sensor.Offset(0, 1).Value" is the recommended way to select cell values next to the input cell (in principle, I would think the input "sensor" would need a type, like "As Address", to be sure we are referring to the cell address, and shifting that with the .Offset(,) method) But again, this part seems to work...
I would be glad for any debugging ideas!
I'm using Excel for Mac 2011.

PHP Code: 

Function calctemp(sensorresistance As Double) As Double

    Dim res 
As Double
    
    Dim K_1 
As DoubleK_2 As DoubleK_3 As DoubleK_4 As Double
    Dim K_5 
As DoubleK_6 As DoubleK_7 As Double
    
    res 
1000 resistance
    K_1 
sensor.Offset(01).Value
    K_2 
sensor.Offset(02).Value
    K_3 
sensor.Offset(03).Value
    K_4 
sensor.Offset(04).Value
    K_5 
sensor.Offset(05).Value
    K_6 
sensor.Offset(06).Value
    K_7 
sensor.Offset(07).Value
    
    calctemp 
K_1 K_2 res K_3 res K_4 res K_5 res K_6 res K_7 res 6
        
End 
Function