range to vba array and use in formula

dave322

New Member
Joined
May 26, 2012
Messages
1
Hello,
i am currently using HoadleyOptions addin but i am struggling to use on of his formulas in vba, don't know if anyone has experience with this but the setup is as follows;
i have 252 daily prices in column A
in cell D1 the result of the following formula should be displayed;
=HoadleyGARCH("V";A1:$A$252;;252;;2)
if i use the formula in excell all works fine but i cant get it to work in vba
hoadley gives following advice with the formula: "Important note: If this function is being called from a VBA module then you must define (or use redim) the number of items in the array to be exactly equal to the number of prices. This principle applies to dividends as well."
right now i have in vba:

Sub Garch()
Dim i As Integer
Dim MyArray()
MyArray = Range("Garch").Value
'check!
For i = LBound(MyArray, 1) To UBound(MyArray, 1)
Range("D1") = HoadleyGarch("V", MyArray, , 252, , 2)
Next i
End Sub

when i run it i get compile error argument not optional.

If anyone has any ideas i would be happy to hear them
thanks
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I'm unfamiliar with this, so just a thought. MyArray as you are using it is a 2-D array. Perhaps Garch wants only a 1-D array, in which case try something like this:
Rich (BB code):
Sub Garch()
Dim j as integer
Dim MyArray()
redim MyArray(1 to Range("Garch").Rows.Count)
For j= 1 to Range("Garch").Rows.Count
MyArray(j) = Range("Garch").Rows(j).value
next j
'check!
Range("D1").Resize( UBound(MyArray)-LBound(MyArray)+1) = HoadleyGarch("V", MyArray, , 252, , 2)
End Sub
Alternatively, perhaps all that's needed is to change:
Rich (BB code):
For i = LBound(MyArray, 1) To UBound(MyArray, 1)
Range("D1") = HoadleyGarch("V", MyArray, , 252, , 2)
Next i
to this
Rich (BB code):
Range("D1").Resize( UBound(MyArray)-LBound(MyArray)+1) = HoadleyGarch("V", MyArray, , 252, , 2)
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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