#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default XNPV in VBA

I'm using Excel 2007 and I'm trying to calculate XNPV for a certain
array within VBA. Within Excel, the XNPV function asks for 3
arguments: XNPV(rate,value,dates), but within VBA, it is only asking
for 2 arguments. When I looked up XNPV within the Excel VBA Help, it
says the function calls for 2 arguments, but gives an example with 3.
When trying to use three arguments I get a compile error with this
message: "Wrong number of arguments or invalid property assignment" I
know it is not an invalid property assignment because I am using the
XIRR function (which only requires 2 arguments) with the same arrays.
Anyone have a solution? Here is code:

Range("H50") = WorksheetFunction.Xirr(NetCFAC, DateSet()) -- THIS
WORKED
Range("D49") = WorksheetFunction.Xnpv(0.05, NetCFAC, DateSet()) --
THIS DOES NOT WORK

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default XNPV in VBA

I see what you are saying but not sure why, looks like a bug.

In the mean time maybe you can use something like this
x = Application.Evaluate("=XNPV(0.1,B1:B5,C1:C5)")

this should also work in earlier versions, as bug or not XNPV was only
introduced as a VBA workksheet function in Excel 2007.

Regards,
Peter T

"David" wrote in message
...
I'm using Excel 2007 and I'm trying to calculate XNPV for a certain
array within VBA. Within Excel, the XNPV function asks for 3
arguments: XNPV(rate,value,dates), but within VBA, it is only asking
for 2 arguments. When I looked up XNPV within the Excel VBA Help, it
says the function calls for 2 arguments, but gives an example with 3.
When trying to use three arguments I get a compile error with this
message: "Wrong number of arguments or invalid property assignment" I
know it is not an invalid property assignment because I am using the
XIRR function (which only requires 2 arguments) with the same arrays.
Anyone have a solution? Here is code:

Range("H50") = WorksheetFunction.Xirr(NetCFAC, DateSet()) -- THIS
WORKED
Range("D49") = WorksheetFunction.Xnpv(0.05, NetCFAC, DateSet()) --
THIS DOES NOT WORK

Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default XNPV in VBA

Good suggestion, unfortunately I'm trying to calculate the XNPV with
arrays built within VBA. When I return this to Excel, it's looking
for Ranges with my VBA names and coming up with a #NAME? error. I
guess I will have to fudge something like this though since it seems
like an unfixable bug.

Thanks for you help
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
XNPV function David Excel Worksheet Functions 2 June 10th 05 02:34 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 07:54 PM.

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"