View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default UDF, Category, Data Type, Format, Using

John,

You are getting the currency worksheet format confused with the currency
data type. The former is in the form £ #,##0.00, whereas this is how defines
the currency data type '... Currency variables are stored as 64-bit (8-byte)
numbers in an integer format, scaled by 10,000 to give a fixed-point number
with 15 digits to the left of the decimal point and 4 digits to the right.
This representation provides a range of -922,337,203,685,477.5808 to
922,337,203,685,477.5807. ...'.

If you don't mind the result as a string (that is. no math on it), you could
try

Public Function PandI(Principal As Long, _
AIR As Single, _
Years As Integer, _
Optional n As Integer = 12) As String
PandI = Format((Principal * AIR / 100 / n * (1 + AIR / 100 / n) _
^ (n * Years)) / ((1 + AIR / 100 / n) ^ (n * Years) - 1), "$#,##0.00")
End FunctionPublic Function PandI(Principal As Long, _
AIR As Single, _
Years As Integer, _
Optional n As Integer = 12) As String
PandI = Format((Principal * AIR / 100 / n * (1 + AIR / 100 / n) _
^ (n * Years)) / ((1 + AIR / 100 / n) ^ (n * Years) - 1), "$#,##0.00")
End Function

otherwise you need to format the cell as currency.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"John Pierce" wrote in message
...
Bob,
Thanks for your response.
I was wondering where you saw my post. I can't find it on
microsoft.public.excel.programming which is where I thought
I had posted it. Anyway, I can let go of the part about
making the function available in the Financial category.
What matters more to me is the way it displays. The result
shows up as 1323.0206 but I want $1,323.02 without having
to format the cell. I thought making the function's
data type currency would do that.

JohnSCPierce

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!