Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Problem using XNPV from VBA

Hello, I have this (to me) strange situation:

Dim aRangeValues() As Double, aRangeDates() As Date

The two arrays are set to the foll. values (dates are in dd/mm/yyyy):

aRangeValues(1) | aRangeValues(2) | aRangeValues(3) | aRangeValues(4)
-1721.9482672 | 194.6875 | 194.6875 | 2194.6875

aRangeDates(1) | aRangeDates(2) | aRangeDates(3) | aRangeDates(4)
27/09/2002 | 30/09/2002 | 30/09/2003 | 30/09/2004



If I try to calculate the NPV (using XNPV - due to different intervals):
Val = Application.Run("XNPV", 0.05, aRangeValues, aRangeDates)
I get the #VALUE! error!

Just to check the situation, I tried to calculate:
Val = Application.Run("XIRR", aRangeValues, aRangeDates)
and I get a correct 0.262366098165512


I tried to use the XNPV function in a cell, and it works!

Any idea?

Thanks, Dario
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Problem using XNPV from VBA

Sub Tester5()
Dim aRangeValues As Variant, bRangeTemp As Variant
Dim aRangeDate() As Long
aRangeValues = Array(-1721.9482672, 194.6875, 194.6875, 2194.6875)
aRangeTemp = Array("09/27/2002", "09/30/2002", "09/30/2003", "09/30/2004")
ReDim aRangeDates(LBound(aRangeTemp) To UBound(aRangeTemp))
For i = LBound(aRangeTemp) To UBound(aRangeTemp)
aRangeDates(i) = CLng(CDate(aRangeTemp(i)))
'Debug.Print aRangeDates(i) ' <== use to check what is in date array
Next
dblRate = 0.05
res = Application.Run("ATPVBAEN.XLA!XNPV", 0.05, aRangeValues, aRangeDates)
Debug.Print res
End Sub

It appears the second argument needs to be an array of longs rather than an
array of dates - got an error when I passed it dates.

Also, Val is a vba function. I would use a different variable than Val.

I put your date in US format - VBA is US centric. Not sure how you are
loading your array of dates, but if using strings at all and using implicit
conversion I would use US formatted strings. If using Cdate, it is supposed
to pay attention to regional settings, but I would check what is in the
array to be sure.


--
Regards,
Tom Ogilvy

Dario wrote in message
m...
Hello, I have this (to me) strange situation:

Dim aRangeValues() As Double, aRangeDates() As Date

The two arrays are set to the foll. values (dates are in dd/mm/yyyy):

aRangeValues(1) | aRangeValues(2) | aRangeValues(3) | aRangeValues(4)
-1721.9482672 | 194.6875 | 194.6875 | 2194.6875

aRangeDates(1) | aRangeDates(2) | aRangeDates(3) | aRangeDates(4)
27/09/2002 | 30/09/2002 | 30/09/2003 | 30/09/2004



If I try to calculate the NPV (using XNPV - due to different intervals):
Val = Application.Run("XNPV", 0.05, aRangeValues, aRangeDates)
I get the #VALUE! error!

Just to check the situation, I tried to calculate:
Val = Application.Run("XIRR", aRangeValues, aRangeDates)
and I get a correct 0.262366098165512


I tried to use the XNPV function in a cell, and it works!

Any idea?

Thanks, Dario



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


Similar Threads
Thread Thread Starter Forum Replies Last Post
NPV vs XNPV Energy Excel Worksheet Functions 7 April 26th 23 11:43 AM
XNPV Scott Excel Discussion (Misc queries) 0 March 31st 06 02:16 PM
NPV vs. XNPV Robert Excel Worksheet Functions 2 March 16th 06 11:46 PM
Formula XNPV Stan Excel Discussion (Misc queries) 3 November 25th 05 05:31 PM
Problem using XNPV from VBA Dario[_2_] Excel Programming 0 July 13th 03 03:47 PM


All times are GMT +1. The time now is 02:00 AM.

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

About Us

"It's about Microsoft Excel"