LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default A useful function: number2text

Are you sick of writting the text expression of a numeric value?
this function change this:

15196739.32

Into this:

FIFTEEN MILLION ONE HUNDRED NINETY SIX THOUNSAND SEVEN HUNDRED THIRT
NINE

Is up to you if you want to use the function, and how to add it to yo
worksheet

Function Number2Text(Number)
a1a19 = Array("ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN"
"EIGHT", "NINE", "TEN", "ELEVEN", "TWELVE", "THIRTEEN", "FOURTEEN"
"FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN", "NINETEEN")
aDecenas = Array("", "TWENTY", "THIRTY", "FOURTY", "FIFTY", "SIXTY"
"SEVENTY", "EIGHTY", "NINETY")
aLlones = Array("THOUNSAND", "MILLION", "BILLION", "TRILLION"
"QUADRILLION", "QUINTILLION", "SEXTILLION", "SEPTILLION", "OCTILLION"
"NONILLION", "DECILLION", "UNDECILLION", "DUODECILLION"
"TREDECILLION")

Number = Str(Number)
Pos = InStr(Number, ".")
If (Pos 0) Then Number = Left(Number, Pos - 1)
If (Val(Number) = 0) Then
Text = "ZERO "
Else
millon = 0
Do
Number = "000" + LTrim(Number) 'Zeros to left to crop smooth
de1a99 = Val(Right(Number, 2))
If (de1a99 0) And (de1a99 < 20) Then
Text = a1a19(de1a99 - 1) + " " + Text
Else
unidad = Val(Right(Number, 1))
If (unidad 0) Then Text = a1a19(unidad - 1) + " " + Text
decena = Val(Left(Right(Number, 2), 1))
If (decena 0) Then Text = aDecenas(decena - 1) + " " + Text
End If
centena = Val(Left(Right(Number, 3), 1))
If (centena 0) Then Text = a1a19(centena - 1) + " HUNDRED "
Text
Number = Left(Number, Len(Number) - 3)
If (Val(Number) 0) Then
Text = aLlones(millon) + " " + Text
millon = millon + 1
End If
Loop While ((Number 0) And (millon < 14))
End If
Number2Text = Text
End Function

I did 2 more functions, one to handle the cents and other with just th
Format as default parameter.

Function Number2Currency(Number, Frm)
Cents = Right(Format(Number, "#.00"), 2)
Text = Number2Text(Number)
If Frm < "" Then
Frm = Replace(Frm, "%", Cents)
End If
Number2Currency = "(" + Text + Frm + ")"
End Function

Function Number2Dollar(Number)
Number2Dollar = Number2Currency(Number, "DOLLARS %/100 U.S.C.Y.")
End Function

About the function, i take the arrays from
credits to him.

Greetings
Robert

--
Message posted from
http://www.ExcelForum.com

 
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
Excel Data Validation/Lookup function does function correcty Kirkey Excel Worksheet Functions 2 May 25th 09 09:22 PM
copy of excel file not showing formulal/function in the function b oaallam Excel Discussion (Misc queries) 4 September 6th 07 01:20 PM
LINKEDRANGE function - a complement to the PULL function (for getting values from a closed workbook) [email protected] Excel Worksheet Functions 0 September 5th 06 03:44 PM
Offset function with nested match function not finding host ss. MKunert Excel Worksheet Functions 1 March 21st 06 10:46 PM
User-Defined Function pre-empting Built-in Function? How to undo???? MarWun Excel Programming 1 August 6th 03 09:31 PM


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