Solved

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

Posted on 2008-10-17
13
600 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

860 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