Help Translating Formula to VBA Code

ttbuson

Board Regular
Joined
Nov 18, 2011
Messages
80
Can someone please help me translate the formula:

{=(SUMSQ(IF(C3:C14-G2>0,0,C3:C14-G2))/COUNT(C3:C14))^(1/2)}

into a VBA user defined function? So far, I have:

(where C3:C14 is the MonthRet and G2 is the MAR in the above formula)

Code:
Function DownsideDev(MonthRet As Range, MAR As Double) As Double
' Calculates Downside Deviation below a Minimum Acceptable Return.
' {=(SUMSQ(IF(C3:C14-G2>0,0,C3:C14-G2))/COUNT(C3:C14))^(1/2)}
Dim i As Integer
Dim DownsidePerf As Double
For i = 1 To MonthRet.Count
    
Next i

End Function

I know it's not much, but I'd really appreciate any help.

Thanks!
tom
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Code:
Function DownsideDev(MonthRet As Range, MAR As Variant) As Double
    ' Calculates Downside Deviation below a Minimum Acceptable Return.
    ' {=(SUMSQ(IF(C3:C14-G2>0,0,C3:C14-G2))/COUNT(C3:C14))^(1/2)}
    Dim cell As Range
    Dim DownsidePerf As Double
    
    For Each cell In MonthRet
        If cell.Value < MAR Then DownsidePerf = DownsidePerf + (cell.Value - MAR) ^ 2
    Next cell
    DownsideDev = (DownsidePerf / Application.Count(MonthRet)) ^ 0.5
    
End Function
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,638
Latest member
Oluwabukunmi

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