range

Good Morning,
I have tried to make this work for 2 hours last night. I think I am doing something stupidly wrong. Would you mind helping me? Please and thanks in anticipation.

Function Rthmal(thick() As Range, lambda() As Range) As Double
Dim Rtemp As Double
Dim i As Integer
Rtemp = 0
For i = LBound(thick) To UBound(thick)
Rtemp = Rtemp + thick(i) / lambda(i)
Next i
Rthmal = Rtemp
End Function

Nick's picture

try this:Function

try this:
Function Rthmal(thick As Range, lambda As Range) As Double
Dim Rtemp As Double
Dim i As Integer
Rtemp = 0
myThick = thick.Value
myLambda = lambda.Value
 
For i = LBound(myThick) To UBound(myThick)
    Rtemp = Rtemp + myThick(i, 1) / myLambda(i, 1)
Next i
 
Rthmal = Rtemp
 
End Function

to test, I entered 1,2,3,4 in range A1 to B2

function call: =rthmal(A1:A2,B1:B2)

function returns: 0.8333

query

first thanks very much for your reply.
unfortunatly, it does not work for me for some reasons. it only works when the data is in column. I have double check with data in row (for instance function call :=rthmal(A1:B1,A2:B2)will return 0.33 (for exact same values above)).
I am even more confused now.
Please help and thanks again,
Deivy

Nick's picture

try this

try this then:

=rthmal(transpose(A1:B1),transpose(A2:B2))