Solved

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

Posted on 2008-10-17
13
598 Views
Last Modified: 2012-05-05
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
Comment
Question by:mcgitsupport
  • 5
  • 5
  • 2
13 Comments
 
LVL 50

Expert Comment

by:Dave Brett
ID: 22740454
To access XIRR you need to enable the Analysis ToolPal addin via Tools - Addins

Regards

Dave
0
 

Author Comment

by:mcgitsupport
ID: 22740503
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
 
LVL 50

Expert Comment

by:Dave Brett
ID: 22740540
In Excel 2003, from the menu
Tools - Addins
and check "Analysis ToolPak"  (both options)

Cheers

Dave
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:mcgitsupport
ID: 22740542
On Excel I had already added the Analysis Toolpak, I'm trying to access the XIRR function in Visual Studio
0
 
LVL 50

Expert Comment

by:Dave Brett
ID: 22740569
the VBA option as well?
0
 

Author Comment

by:mcgitsupport
ID: 22740581
Yes, I have them both.
0
 
LVL 50

Expert Comment

by:Dave Brett
ID: 22740634
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
 

Author Comment

by:mcgitsupport
ID: 22740787
I'm using Visual Studio as my editor and I can't that reference.  Any other options? How about your code?
0
 
LVL 92

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 55 total points
ID: 22741468
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
 
LVL 50

Accepted Solution

by:
Dave Brett earned 70 total points
ID: 22744269
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
 

Author Comment

by:mcgitsupport
ID: 22975714
Since I was not able to use the XIRR from excel, I used VB code.
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 22976022
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

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question