On Wed, 19 Sep 2007 13:26:02 -0700, Laurie
<(E-Mail Removed)> wrote:
>Hi,
>
>I need to create a UDF to return an array of values with some specified
>input variables/values, like inputing the interest rates and a set of periods
>of time to get an array of annuity factors.
>
>How can I do this?
>
Here's an example of a UDF that returns an array
Public Function Factors(rRates As Range, rDays As Range)
Dim aReturn() As Double
Dim rCell As Range
Dim i As Long
ReDim aReturn(1 To rRates.Cells.Count)
i = 0
For Each rCell In rRates.Cells
i = i + 1
aReturn(i) = rCell.Value / 365 * rDays(i).Value
Next rCell
Factors = aReturn
End Function
The variable aReturn holds all the return values and the function name is
set equal to this array variable at the end of the function.
Note that it assumed that rRates and rDays are ranges with the same number
of cells that correlate in some way, but there is no error-checking to make
sure that's the case.
--
Dick Kusleika
Microsoft MVP-Excel
http://www.dailydoseofexcel.com