PC Review


Reply
Thread Tools Rate Thread

How to create a UDF to return an array of values with input variab

 
 
=?Utf-8?B?TGF1cmll?=
Guest
Posts: n/a
 
      19th Sep 2007
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?

I really appreciate any help in this issue.

Thanks a lot in advance,
Laurie


 
Reply With Quote
 
 
 
 
=?Utf-8?B?R2FyeScncyBTdHVkZW50?=
Guest
Posts: n/a
 
      19th Sep 2007
Function laurie() As Variant
v = Array(1, 2, 3)
laurie = v
End Function


In the worksheet, select cells A1, B1, C1
type:
=laurie() and complete with CNTRL-SHIFT-ENTER
--
Gary''s Student - gsnu200745


"Laurie" 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?
>
> I really appreciate any help in this issue.
>
> Thanks a lot in advance,
> Laurie
>
>

 
Reply With Quote
 
Dick Kusleika
Guest
Posts: n/a
 
      19th Sep 2007
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
 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      20th Sep 2007
Laurie,

See the sections entitled "Returning Arrays From Functions" and "Returning
Arrays With Two Dimensions" on the page
http://www.cpearson.com/Excel/Writin...ionsInVBA.aspx

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"Laurie" <(E-Mail Removed)> wrote in message
news:68C7FFB5-8341-4C72-B2EC-(E-Mail Removed)...
> 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?
>
> I really appreciate any help in this issue.
>
> Thanks a lot in advance,
> Laurie
>
>


 
Reply With Quote
 
=?Utf-8?B?TGF1cmll?=
Guest
Posts: n/a
 
      20th Sep 2007
Thanks for the big help, Chip, Dick and Gary''s Student!!

Now I know how to create a UDF returning arrays (one or two dimensional),
which is great and is what I was exactly looking for.

The next question is that how I can refer to the resulted arrays in another
UDF to do other calculations? Like referring to a specific element in the
array one at a time in another UDF.


Thank you all again!!!!!!

Sincerely,
Laurie



"Chip Pearson" wrote:

> Laurie,
>
> See the sections entitled "Returning Arrays From Functions" and "Returning
> Arrays With Two Dimensions" on the page
> http://www.cpearson.com/Excel/Writin...ionsInVBA.aspx
>
> --
> Cordially,
> Chip Pearson
> Microsoft MVP - Excel
> Pearson Software Consulting
> www.cpearson.com
> (email on the web site)
>
> "Laurie" <(E-Mail Removed)> wrote in message
> news:68C7FFB5-8341-4C72-B2EC-(E-Mail Removed)...
> > 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?
> >
> > I really appreciate any help in this issue.
> >
> > Thanks a lot in advance,
> > Laurie
> >
> >

>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to return an array of values that are not zero/Null apache007 Microsoft Excel Misc 13 15th May 2009 06:00 AM
How to return an array of values that are not zero/Null apache007 Microsoft Excel Misc 0 8th May 2009 01:57 AM
Input and return values =?Utf-8?B?VG9ueU0=?= Microsoft Access 3 12th Apr 2006 07:48 PM
Use array to return array of values =?Utf-8?B?QnJhZA==?= Microsoft Excel Worksheet Functions 2 30th Mar 2006 05:58 PM
VBA Syntax for VLOOKUP to return array of return values Alan Beban Microsoft Excel Programming 7 5th Aug 2003 11:41 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:34 PM.