Brad said:
I'm willing to have my UDF, but not sure how that would be done.
The following UDF seems to have the same results for comparable Excel XIRR
usage.
For Excel 2003, you must select the add-in "Analysis ToolPak - VBA" in Excel
(Tools > Add-ins), and you must select the reference "atpvbaen.xls" in VBA
(Tools > References).
The UDF should work with your examples, when written correctly:
=myXIRR((m3:m4,n5), d3:d5)
=myXIRR((m3:m40,n41), d3:d41)
However, for thorough testing of any solution, I suggest that you set B1:B7
to the values -10000, 2000, 3000, 4000, 5000, 6000, 7000, and set C1:C7 to
the dates 1/1/2011 through 1/1/2017. Then....
1. Compare to the following, all of which should return the same valid
result (about 29.79%):
=XIRR(B1:B7, C1:C7)
=myXIRR(B1:B7, C1:C7)
=myXIRR((B1,B2:B6,B7), (C1:C2,C3,C4,C5:C7))
=myXIRR({-10000,2000,3000,4000,5000,6000,7000}, C1:C7)
2. Compare the following error conditions:
a. =XIRR({-1E9,1}, C1:C2)
=myXIRR({-1E9,1}, C1:C2)
b. =XIRR({-10000}, C1)
=myXIRR({-10000}, C1)
c. =XIRR(-10000, C1)
=myXIRR(-10000, C1)
d. =XIRR("hi", C1)
=myXIRR("hi", C1)
To enter the UDF, copy the following text. In Excel, press alt+F11. In
VBA, click Insert > Module, then paste into the VBA editor pane. Also see
the special steps for Excel 2003 above.
The UDF....
Option Explicit
Function myXIRR(v, d, Optional g As Double = 0.1)
Dim vv, dd, c, i As Long, nv As Long, nd As Long
Select Case TypeName(v)
Case "Range": nv = v.Count
Case "Variant()": nv = UBound(v)
Case "Double": GoTo naError
Case Else: GoTo valerror
End Select
Select Case TypeName(d)
Case "Range": nd = d.Count
Case "Variant()": nd = UBound(d)
Case "Double": GoTo naError
Case Else: GoTo valerror
End Select
ReDim vv(1 To nv)
ReDim dd(1 To nd)
i = 0: For Each c In v: i = i + 1: vv(i) = c: Next
i = 0: For Each c In d: i = i + 1: dd(i) = c: Next
myXIRR = xirr(vv, dd, g)
Exit Function
naError: myXIRR = CVErr(xlErrNA): Exit Function
valerror: myXIRR = CVErr(xlErrValue)
End Function
----- original message -----