Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default reference to range in function within code

Hi Paul,

You can pass the 3D array just the same, and just look at the first
dimension, as you did with tyhe first column.

I haven't tested this, but I hope I haven't missed anything.

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, 1) Then
nRow = 1
Else
For nRow = 1 To UBound(TRange,1)
If T = TRange(i, 1) Then Exit For
Next nRow
If nRow = UBound(TRange,1) Then
nRow = nRow - 1
End If
End If

TLow = TRange(nRow, 1)
THigh = TRange(nRow + 1, 1)
LLow = LRange(nRow, 1)
LHigh = LRange(nRow + 1, 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 Bob,

that's probably the solution ... the problem is that I don't know how
the assign one dimension of a multidimension array to the function ...
if i succeed in naming the specific dimension (of the multidimension
array) I can use that name in the interpolation.

regards,

paul



"Bob Phillips" wrote in message

...
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.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
INDIRECT function to reference a named range iperlovsky Excel Worksheet Functions 2 November 6th 09 06:09 AM
VBA code for find function (reference cell value) emil Excel Worksheet Functions 0 May 5th 09 01:57 AM
ComboBox AddItem code to reference cells in a Range HBC_MT Excel Discussion (Misc queries) 0 February 26th 09 04:05 PM
A function to get a variable row reference for range in XNPV funct Tex1960 Excel Worksheet Functions 6 August 1st 05 11:20 PM
dynamic range reference and use of common code clui[_4_] Excel Programming 2 December 2nd 03 05:45 PM


All times are GMT +1. The time now is 02:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"