October 29th, 2003, 3:43 am
A few suggestions:- always use option explicit- I like using option base 1, gets you rid of the n-1 nonsenseTry the following:sub test() Dim cash_flow() as double, payout_dates() as date, n as long, discount as double, ans as doublen = range("cash_flow").countredim cash_flow(n) redim payout_dates(n) for i = 0 to n- 1 cash_flow(i) = range("cash_flow").cells(i,0).value payout_dates(i) = range("payout_dates").cells(i,0).value next i discount_rate = range("discount_rate").value ans = xnpv(discount_rate,cash_flow,payout_dates) End sub________Appreciate the suggestions. However, I still get the type-mismatch run-time error on the last line, the problem being that the second and third arguments of xnpv are required to be ranges and not arrays of double and date, respectively. Doesn't VBA afford the facility of type-casting these into ranges ?