Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-10-17
13
Medium Priority
?
621 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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 93

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 220 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 280 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 93

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
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…

722 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