View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default reference to range in function within code

Paul,

You could drop the arrays into a worksheet range, but why don't you pass
arrays to the function and process these?

Function VLinearInterpolation(T As Double, TRange , _
LRange ) As Double
Dim nRow As Integer
Dim TLow As Double
Dim THigh As Double
Dim LLow As Double
Dim LHigh As Double

'If at top or bottom, use two points at the end to extrapolate
If T < TRange(1) Then
nRow = 1
Else
For nRow = 1 To UBound(TRange,1)
If T = TRange(i) Then Exit For
Next nRow
If nRow = UBound(TRange,1) Then
nRow = nRow - 1
End If
End If

TLow = TRange(nRow,)
THigh = TRange(nRow + 1)
LLow = LRange(nRow)
LHigh = LRange(nRow + 1)
VLinearInterpolation = (T - TLow) * (LHigh - LLow) / (THigh -
TLow) + LLow

End Function

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Paul" wrote in message
om...
Hi all,

Below I have provided the code (Sub bereken_asian_call) for a macro
which finally calculates two arrays: O(index,state,a) and
F(index,state,a). The range for the a values in this case is 1 to
alpha (which is 4 now).
Additionally, a new value is calculated called NewAv1.

I should now interpolate NewAv1 given the array O(index,state,1 to
alpha) and F(index,state,1 to alpha). For that I want to use a
function written in VBA called VlinearInterpolation (see below).
Therefore, I must therefore to that function within the sub
bereken_asian_call. The function is defined as:
VlinearInterpolation(value to be interpolated, range 1, range 2) ...

In my case range 1 is: O(index,state,1 to alpha) and range 2 is
F(index,state,1 to alpha) ...

Question is: how should i refer to the VLinearInterpolation function
and how do I assign the O(index,state,1 to alpha) and F(index,state,1
to alpha) ranges to range 1, respectively range 2 in the
VLinearInterpolation function.