Trying to output a 1x10 array

maxoliver100

New Member
Joined
Dec 19, 2013
Messages
18
Hi Guys please help !!! I am new to VBA and trying to output a 1x10 array of the function FwdRate. The inputs are all 1x10 horizontal ranges of numbers. So for example to calculate FwdRate 1 I need to take the first values from each of the input ranges and enter them into the formula below ! Where am I going wrong as all I get is the VALUE error when I press ctrl+shift+enter ??
Thanks Max

Option Explicit


Function FwdRate(Tau As Range, f1 As Range, dtau As Range, vol1 As Range, vol2 As Range, vol3 As Range, m As Range) As Variant


Dim VArray() As Double
Dim i As Integer
Dim n As Integer
Dim dt As Double
Dim X1, X2, X3 As Double


n = Tau.Columns.Count


ReDim VArray(1 To 1, 1 To n)


dt = 0.01
X1 = BoxMuller()
X2 = BoxMuller()
X3 = BoxMuller()


For i = 1 To n

VArray(1, i) = f1(1, i) + m(1, i) * dt + (vol1(1, i) * X1 + vol2(1, i) * X2 + vol3(1, i) * X3) * Sqr(dt) _
+ ((f1(1, i + 1) - f1(1, i)) / dtau(1, i)) * dt

Next i

FwdRate = VArray

End Function
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Hi Guys please help !!! I am new to VBA and trying to output a 1x10 array of the function FwdRate. The inputs are all 1x10 horizontal ranges of numbers. So for example to calculate FwdRate 1 I need to take the first values from each of the input ranges and enter them into the formula below ! Where am I going wrong as all I get is the VALUE error when I press ctrl+shift+enter ??
Thanks Max

Option Explicit


Function FwdRate(Tau As Range, f1 As Range, dtau As Range, vol1 As Range, vol2 As Range, vol3 As Range, m As Range) As Variant


Dim VArray() As Double
Dim i As Integer
Dim n As Integer
Dim dt As Double
Dim X1, X2, X3 As Double


n = Tau.Columns.Count


ReDim VArray(1 To 1, 1 To n)


dt = 0.01
X1 = BoxMuller()
X2 = BoxMuller()
X3 = BoxMuller()


For i = 1 To n

VArray(1, i) = f1(1, i) + m(1, i) * dt + (vol1(1, i) * X1 + vol2(1, i) * X2 + vol3(1, i) * X3) * Sqr(dt) _
+ ((f1(1, i + 1) - f1(1, i)) / dtau(1, i)) * dt

Next i

FwdRate = VArray

End Function
Untested, but I think to make this function work, you will have to select the 10 cells the array will be distributed first, then put your formula into the Formula Bar and press CTRL+SHIFT+ENTER.
 
Upvote 0

Forum statistics

Threads
1,215,488
Messages
6,125,092
Members
449,206
Latest member
ralemanygarcia

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