Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Range as argument in function

For a function that returns array, the user has to select the appropriate
number of cells and then type the formula and press ctrl+shift+enter. Is it
possible in the following function to add another argument for the range
where the output will be printed. so that the user can select it (or type
the range) as an argument?

Thanks. ~Asif

Function SLV(Rental As Long, Term As Integer, Optional NumRenPaid, Optional
DiscRate = 0.12)


Dim TVal As Double
TVal = 0

ReDim presval(Term) As Double

Dim yr As Integer
yr = Int(Term / 12)

ReDim an(yr + 1) As Long

Dim RemMon As Integer
RemMon = Term Mod 12

Dim i As Integer

'Take correct upperbound of "an" array depending on whether RemMon is 0
or not.
If RemMon = 0 Then
ReDim an(yr) As Long
For i = 1 To Term
presval(i) = Rental / (1 + DiscRate / 12) ^ (i - 1)
TVal = TVal + presval(i)

If i Mod 12 = 0 Then
an(yr) = CLng(TVal)
yr = yr - 1
End If
Next i
Else
ReDim an(yr + 1) As Long
For i = 1 To Term
presval(i) = Rental / (1 + DiscRate / 12) ^ (i - 1)
TVal = TVal + presval(i)

If i = RemMon Then
an(yr + 1) = TVal
ElseIf (i - RemMon) Mod 12 = 0 Then
an(yr) = CLng(TVal)
yr = yr - 1
End If
Next i
End If

SLV = Application.Transpose(an)

End Function









  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Range as argument in function

Asif,

Functions cannot modify any cell other than the ones from which
it was called, so you can't have a destination as an argument to
the function.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Asif" wrote in message
...
For a function that returns array, the user has to select the

appropriate
number of cells and then type the formula and press

ctrl+shift+enter. Is it
possible in the following function to add another argument for

the range
where the output will be printed. so that the user can select

it (or type
the range) as an argument?

Thanks. ~Asif

Function SLV(Rental As Long, Term As Integer, Optional

NumRenPaid, Optional
DiscRate = 0.12)


Dim TVal As Double
TVal = 0

ReDim presval(Term) As Double

Dim yr As Integer
yr = Int(Term / 12)

ReDim an(yr + 1) As Long

Dim RemMon As Integer
RemMon = Term Mod 12

Dim i As Integer

'Take correct upperbound of "an" array depending on whether

RemMon is 0
or not.
If RemMon = 0 Then
ReDim an(yr) As Long
For i = 1 To Term
presval(i) = Rental / (1 + DiscRate / 12) ^

(i - 1)
TVal = TVal + presval(i)

If i Mod 12 = 0 Then
an(yr) = CLng(TVal)
yr = yr - 1
End If
Next i
Else
ReDim an(yr + 1) As Long
For i = 1 To Term
presval(i) = Rental / (1 + DiscRate / 12) ^

(i - 1)
TVal = TVal + presval(i)

If i = RemMon Then
an(yr + 1) = TVal
ElseIf (i - RemMon) Mod 12 = 0 Then
an(yr) = CLng(TVal)
yr = yr - 1
End If
Next i
End If

SLV = Application.Transpose(an)

End Function











  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Range as argument in function

Not sure what you are trying to achieve. The output is determined by where
you array enter the formula. What role would entering that range as a
argument play.

--
Regards,
Tom Ogilvy



"Asif" wrote in message
...
For a function that returns array, the user has to select the appropriate
number of cells and then type the formula and press ctrl+shift+enter. Is

it
possible in the following function to add another argument for the range
where the output will be printed. so that the user can select it (or type
the range) as an argument?

Thanks. ~Asif

Function SLV(Rental As Long, Term As Integer, Optional NumRenPaid,

Optional
DiscRate = 0.12)


Dim TVal As Double
TVal = 0

ReDim presval(Term) As Double

Dim yr As Integer
yr = Int(Term / 12)

ReDim an(yr + 1) As Long

Dim RemMon As Integer
RemMon = Term Mod 12

Dim i As Integer

'Take correct upperbound of "an" array depending on whether RemMon is

0
or not.
If RemMon = 0 Then
ReDim an(yr) As Long
For i = 1 To Term
presval(i) = Rental / (1 + DiscRate / 12) ^ (i - 1)
TVal = TVal + presval(i)

If i Mod 12 = 0 Then
an(yr) = CLng(TVal)
yr = yr - 1
End If
Next i
Else
ReDim an(yr + 1) As Long
For i = 1 To Term
presval(i) = Rental / (1 + DiscRate / 12) ^ (i - 1)
TVal = TVal + presval(i)

If i = RemMon Then
an(yr + 1) = TVal
ElseIf (i - RemMon) Mod 12 = 0 Then
an(yr) = CLng(TVal)
yr = yr - 1
End If
Next i
End If

SLV = Application.Transpose(an)

End Function











  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 15
Default Range as argument in function

The range as an argument will be the destination of the output. But I guess
Chip Pearson has already answered that it's not possible. Thanks.

Tom Ogilvy wrote in message ...
Not sure what you are trying to achieve. The output is determined by

where
you array enter the formula. What role would entering that range as a
argument play.

--
Regards,
Tom Ogilvy




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
Passing a range name as an argument to the Index Function Michael Sharpe Excel Discussion (Misc queries) 3 September 5th 12 01:33 PM
Which argument can be replaced by a Tag rather than a cell range? dwest4624 Excel Discussion (Misc queries) 0 July 21st 09 08:54 PM
Need to get Address() to Average Function Range argument Tweedy Excel Worksheet Functions 6 April 27th 09 10:21 PM
Passing range as argument Jan Kronsell[_2_] Excel Programming 3 September 3rd 03 12:31 PM
how to? set my range= my UDF argument (range vs. value in range) [advanced?] Keith R[_3_] Excel Programming 2 August 11th 03 05:55 PM


All times are GMT +1. The time now is 07:15 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"