1. Using the [#] icon to add CODE tags
2. Using Option Explicit to ensure all variables are properly Dim-ed
3. Using explicitly typed function return variables
4. Not sure about your nNPV logic since it doesn't match the WS function so I changed it
5. In ComputePV you have to pass cf() not just cf to get it to compile
Option Explicit
Function nNPV(Rate As Double, R As Range) As Double
Dim ary As Variant
Dim r1 As Range
Set r1 = Range(R.Cells(1, 1), R.Cells(1, 1).End(xlToRight))
ary = Application.WorksheetFunction.Transpose(Application.WorksheetFunction.Transpose(r1.Rows(1)))
nNPV = Application.WorksheetFunction.NPV(Rate, ary)
End Function
Function NewDynPV(R As Range) As Variant
Dim n As Integer 'Number of periods
Dim cf() As Double
Dim i As Long
n = GetN(R)
If (n = 0) Then
NewDynPV = n
Exit Function
End If
ReDim cf(1 To n)
For i = 1 To n
cf(i) = R(i)
Next I
NewDynPV = ComputePV(cf)
End Function
Function ComputePV(cf() As Double) As Double 'Auxiliary function
Dim Temp As Double
Dim i As Long
Temp = 0
For i = LBound(cf) To UBound(cf) 'From time 0 to time n
Temp = Temp + cf(i) / 1.05 ^ I
Next I
ComputePV = Temp
End Function
Function GetN(R As Range) As Long 'Auxiliary Function to get number of elements in R
If R.Columns.Count = 1 Then
GetN = R.Rows.Count
ElseIf R.Rows.Count = 1 Then
GetN = R.Columns.Count
Else
GetN = 0
End If
End Function