Solved

Pb with calling Excel Function XIRR from VB

Posted on 2003-12-12
3
912 Views
Last Modified: 2012-05-04
Hi,

I'm unsuccessfully trying for a few days to call a XIRR EXCEL function from visual-basic.

In a VB process, I need to calculate the Internal rate of return for nonperiodic cash flow.
As such a financial function is not available in vb, I'd like to use the Excell XIRR function.

I found 2 ways for calling such a function from VB, but none worked :-(  :
Set XlAppl = createobject("Excel.application")
XlAppl.workbooks.open xlappl.librarypath & "\Analysis\ATPVBAEN.XLA"
XlAppl.Workbooks("ATPVBAEN.XLA").runautomacros (xlAutoOpen)

1st solution :
(the following values are actually coming from a recordset)
wResult = XlAppl.Run("ATPVBAEN.XLA!XIRR","-10000,2750,2750,2750","12/31/1998,07/31/1999,12/31/2000,07/31/2001",0.1)
This gives wResult = 'Error 2015' !!
I'm not sure of the format to use for dates and for separators but none of my trials was successfull.

2nd solution :
XlAppl.Workbooks.add
XlAppl.Cells(1,1).value=-10000
XlAppl.Cells(1,2).value= "12/31/1998"
XlAppl.Cells(2,2).value=2750
XlAppl.Cells(2,2).value= "07/31/1999"
XlAppl.Cells(3,1).value=2750
XlAppl.Cells(3,2).value= "12/31/2000"
XlAppl.Cells(4,1).value=2750
XlAppl.Cells(4,2).value= "07/31/2001"
XlAppl.Cells(1,3).value=0.1
XlAppl.Cells(1,4).formula= "=xirr(A1:A4,B1:B4,C1)"
Xlappl.calculate
wResult=XlAppl.Cells(1,4).value
This gives wResult = "Error 2036" !!

I certainly missed something...

Any suggestion should be appreciated
Thanks

Yves
0
Comment
Question by:ymiossec
  • 2
3 Comments
 
LVL 9

Expert Comment

by:Dang123
ID: 9928410
Yves,
    In help for the XIRR function, it says: "If this function is not available, run the Setup program to install the Analysis ToolPak. After you install the Analysis ToolPak, you must enable it by using the Add-Ins command on the Tools menu." Is the ToolPak enabled on your machine?

    Also, there is a typo in your second sample.
   
XlAppl.Cells(2,2).value=2750
XlAppl.Cells(2,2).value= "07/31/1999"

should be

XlAppl.Cells(1,2).value=2750
XlAppl.Cells(2,2).value= "07/31/1999"


Dang123
0
 
LVL 2

Expert Comment

by:rhys_kirk
ID: 9928670
Check this out...

VB Version of the XIRR function....

http://www.entisoft.com/ESTools/MathFinancial_XIRRSample.HTML
0
 
LVL 2

Accepted Solution

by:
rhys_kirk earned 500 total points
ID: 9928718
Actually, an actual VB project that calculate XIRR is here....

http://www.programmersheaven.com/zone1/cat373/23046.htm
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

Title # Comments Views Activity
VB6 ListBox Question 4 48
Create Files based on Cell Values in a Range in Excel 12 43
backup program with robocopy 6 43
adding "ungroup sheets" to existing vbs code 5 29
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

839 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