Solved

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

Posted on 2008-10-17
13
595 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
 

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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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 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…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now