LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
JF3 JF3 is offline
external usenet poster
 
Posts: 1
Default Allowing a UDF to

Hi all,

I have a UDF(see below) that gives me the interest payment on a certain
date based on an actual/360 basis. It currently accepts single values
or single cell references for each of the arguments. I would like to
be able to use this function as an array function. That is, I would
like to be able to pass any combination of a range, a single cell
reference or a value for each argument and return an array when I hit
Ctrl+Shift+Enter. (that I could as an argument for the sum(), avg(),
min() or max() functions). You can do this with the IPMT() function
that ships with excel(I think in the analysis pack add-in). My
questions are..

Is there an easy way to make my Function Accept ranges for any or all
of the arguments and return an array when I hit ctrl+Shift+enter? My
guess is no.

Alternatively, is there a framework or best practice for creating
functions that can work as a single or array function?....I imagine you
would want to first check and see if any of the values passed are a
range. if not just use the normal logic and return 1 value. If there
are multi-cell ranges then you have to first make sure all of the
arguments are either a single cell/value and that all the arguments
that have multiple cell ranges all have the same number of cells. Then
I guess you might assign the arguments to a multidimensional
array(assigning the same value for every row where an argument
referenced a single cell/value) and run each element through the
calculations, depositing the results in another array that you will
return....Or You could create array's for only those arguments that
reference a range and run through all the arguments that way
referencing single value variables or arrays as appropriate.

Please let me know if you have any suggestions or if you know of any
posting anywhere. Any and all help is appreciated!

P.S. Sorry for the long post.


Public Function Act360IPMT(OrigBal As Double, OrigPmtDate As Date,
pmtDate As Date, Ammort As Long, Rate As Double, Optional SvcFee As
Double = 0) As Double
the same day.

'Some validation code will appear here

Dim CurrentPmtdate As Date
Dim CurrentBal As Double
Dim PmtAmount As Double

CurrentPmtdate = OrigPmtDate
CurrentBal = OrigBal
PmtAmount = -Pmt(Rate / 12, Ammort, OrigBal)

Do While CurrentPmtdate < pmtDate
CurrentBal = CurrentBal - (PmtAmount - ((CurrentPmtdate -
DateAdd("m", -1, CurrentPmtdate)) / 360) * Rate * CurrentBal)
CurrentPmtdate = DateAdd("m", 1, CurrentPmtdate)
Loop

Act360IPMT = Round((((CurrentPmtdate - DateAdd("m", -1,
CurrentPmtdate)) / 360) * Rate * CurrentBal) - (CurrentBal * SvcFee *
30 / 360), 2)

End Function

 
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
allowing each value to be used once Football Express Excel Worksheet Functions 9 October 18th 09 12:01 AM
DropDowns - allowing each value to be used once Football Express New Users to Excel 3 September 7th 09 01:58 PM
Allowing Only Certain Entrees George Excel Worksheet Functions 3 September 25th 07 08:03 PM
Allowing a leading zero if there is one RontheWrench Excel Discussion (Misc queries) 2 June 26th 07 09:36 PM
Allowing entry only once Adam Excel Programming 2 June 16th 05 01:51 AM


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