In excel, the formula must be recognized as Array, so when I type in it, press Ctrl Shift Enter to get the {} brackets around the formula.
Does anyone know how to do this?
I want to be able to input only returns_calc() and select the range that fits the returns variable below.
{=(PRODUCT(1+returns/100) -1)*100}
Sub Sample()
MsgBox Application .Evaluate(["=(PRODUCT(1+returns/100)-1)*100"])
End Sub
Now modify it to accept the range in the function, you can also do this Do
Function returns_calc(rng As Range) As Variant
On Error GoTo Whoa
Dim frmulaStr As String
frmulaStr = "=(PRODUCT(1+(" & rng.Address & ")/100)-1)*100"
returns_calc = Application.Evaluate([frmulaStr])
Exit Function
Whoa:
returns_calc = "Please check formula string"'or simply returns_calc = ""
End Function
Sample screenshot
div>
I am trying to put the following formula into the UDF in order to get a cumulative return when summarizing monthly returns.
In excel, the formula must be recognized as an array, So when I type in it, I press Ctrl Shift Enter to get the {} brackets around the formula.
Does anyone know how to do this?
I want to be able to input only returns_calc() and select the range that fits the returns variable below.
{=(PRODUCT(1+returns/100) -1)*100}
You can use the [] notation in Application.Evaluate to calculate the array formula in VBA. You can only Call the above formula in one line, as shown below
Sub Sample()
MsgBox Application.Evaluate(["=(PRODUCT(1+returns /100)-1)*100"])
End Sub
Now modify it to accept the range in the function, you can also do this
Function returns_calc(rng As Range) As Variant
On Error GoTo Whoa
Dim frmulaStr As String
frmulaStr = "=(PRODUCT(1+( "& rng.Address & ")/100)-1)*100"
returns_calc = Application.Evaluate([frmulaStr])
Exit Function
Whoa:
returns_calc = "Please check formula string"'or simply returns_calc = ""
End Function
Sample screenshot
WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2351 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC