Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default UDF with IRR

Trying get a simple function to work - want to calculate the IRR of a
data set using VBA and not a formula. Keep getting an error: Here's
what I have:

Data:
-1000
300
300
300
300

Code:
Function testi(ArrayIn As Double)

ReDim ArrayIn(5) As Double

testi = IRR(ArrayIn(), 0.1)

End Function

Any ideas on how I can get this to work would be greatly appreciated.

Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default UDF with IRR

I can get IRR to work if I create a reference to it. however, using
application.Run which works with most Analysis toolpak functions doesn't seem
to work with IRR (at least I couldn't get it to).

Here is a workaround:

Sub AAtest1()
Dim s As String
Dim v(0 To 4) As Double
v(0) = -1000
v(1) = 300
v(2) = 300
v(3) = 300
v(4) = 300
s = "{"

For i = LBound(v) To UBound(v)
s = s & v(i) & ","
Next
s = Left(s, Len(s) - 1) & "}"
MsgBox testi(s)
End Sub


Function testi(s As String)
testi = Evaluate("IRR(" & s & ", 0.1)")
End Function

This will be limited as to the number of payments you can include since
Evaluate chokes for character strings longer than about 255.

Otherwise, create the reference.

--
Regards,
Tom Ogilvy


" wrote:

Trying get a simple function to work - want to calculate the IRR of a
data set using VBA and not a formula. Keep getting an error: Here's
what I have:

Data:
-1000
300
300
300
300

Code:
Function testi(ArrayIn As Double)

ReDim ArrayIn(5) As Double

testi = IRR(ArrayIn(), 0.1)

End Function

Any ideas on how I can get this to work would be greatly appreciated.

Thanks.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default UDF with IRR

Here's a solution that I just stumbled upon that seems to work:

Public Function testi(ArrayIn As Range) As Double

testi = Application.WorksheetFunction.IRR(ArrayIn(), 0.1)

End Function

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default UDF with IRR

This work to

Public Function testi(ArrayIn As Range) As Double

testi= Application.IRR(ArrayIN, 0.1)

End Function

Regards

Luis Fernando Ortiz Maldonado


escribió en el mensaje
oups.com...
Here's a solution that I just stumbled upon that seems to work:

Public Function testi(ArrayIn As Range) As Double

testi = Application.WorksheetFunction.IRR(ArrayIn(), 0.1)

End Function



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:14 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"