• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 647
  • Last Modified:

Cannot find the XIRR function in the list of WorksheetFunction on VB.NET project

I'm trying to call the XIRR function on my VB.NET project but it's not listed in the available options.  I have made a reference to Microsoft Excel 11.0 Object Library but it seems like I need a newer version or some other reference.  If you look at my code below I can access the IRR function but not XIRR.  Thanks for your help!
Imports Microsoft.Office.Interop
 
  Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
 
Dim oXL As New Excel.Application
 
Dim result As Double = oXL.WorksheetFunction.Irr(Cash, 0.1)
 
End Sub

Open in new window

0
mcgitsupport
Asked:
mcgitsupport
  • 5
  • 5
  • 2
2 Solutions
 
DaveCommented:
To access XIRR you need to enable the Analysis ToolPal addin via Tools - Addins

Regards

Dave
0
 
mcgitsupportAuthor Commented:
Dave, I'm using Visual Studio 2005 and have Excel 2003 installed.  Can you be a little more specific on how I can enable the addin? Thanks!
0
 
DaveCommented:
In Excel 2003, from the menu
Tools - Addins
and check "Analysis ToolPak"  (both options)

Cheers

Dave
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
mcgitsupportAuthor Commented:
On Excel I had already added the Analysis Toolpak, I'm trying to access the XIRR function in Visual Studio
0
 
DaveCommented:
the VBA option as well?
0
 
mcgitsupportAuthor Commented:
Yes, I have them both.
0
 
DaveCommented:
Ok. In the VB Editor, go to Tools/References, and be sure there's a check mark in front of ATPVBAEN.XLS

I don't have a good feel for Visual Studio, so there may be an issue here beyond the VBA settings. . If this doesn't work then I do have a VBA user function that calculates XIRR

Cheers

Daver
0
 
mcgitsupportAuthor Commented:
I'm using Visual Studio as my editor and I can't that reference.  Any other options? How about your code?
0
 
Patrick MatthewsCommented:
Hello mcgitsupport,

Dave is giving you great help on enabling XIRR() in your project.  That said, here is my standard screed
against all things related to IRR:

I urge you to be very careful in using internal rates of return.  IRR--the finance construct
itself, and not just the Excel functions IRR(), XIRR(), and MIRR()--is, simply put, not reliable,
and prioritizing investment decisions on an IRR basis can lead to bad decision-making.  You
should use net present value (NPV) instead.

1) Depending on the nature of the cash flows, there can actually be more than one IRR.
(The number of IRR results will match the number of times the stream of cash flows
changes signs.)

2) Some scenarios can have very high IRR but actually have negative NPV using any
rational discount rate.

Illustrating both...  Consider the following cash flows:

Today, -1,600
1 year from now, 10,000
2 yrs from now, -10,000

This stream actually has two IRRs: 25%, and 400%, both of which sure look attractive.  Yet,
any reasonable discount yields a negative NPV.

Bottom line: trust NPV, and eschew IRR.

Regards,

Patrick
0
 
DaveCommented:
The XIRR formula in this VBA function also contains MIRR - ie an assumption around the return on any cashflow spun off by the project.
http://j-walk.com/ss/excel/eee/eee017.txt

Patrick,

I agree completely :)
http://www.dailydoseofexcel.com/archives/2005/01/13/charitable-contributions-and-irr/ 

The MIRR addresses some of the limitations but it's still a tricky metric

Cheers

Dave
0
 
mcgitsupportAuthor Commented:
Since I was not able to use the XIRR from excel, I used VB code.
0
 
Patrick MatthewsCommented:
I object.  At the very least, Dave should get the answer for having provided two avenues of attack (even if the referencing to the Analysis Toolpak did not work, the code for the IRR UDF Dave linked to could have been adapted).

It would be nice, but not necessary, if I got a share for my general warning regarding the unreliability of IRR under any circumstances.

Patrick
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 5
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now