Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default Can you convert numbers to words - 800 as eight hundred

I need to display numbers as words in a legal document so I need to convert a
numbers to words
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 698
Default Can you convert numbers to words - 800 as eight hundred

See if this helps...

I altered a function I wrote:

Paste the below VBA code into a general module
€¢ Hold [Alt] and press [F11]€¦..to view the visual basic editor
€¢ Select the workbook you want to use the function in
€¢ From the main menu: <insert<module
€¢ Copy the below code and paste it into the blank module

Now use the NumsToWords() function to convert numbers to a word phrase.
Example:
A3: 800
A4: =NumsToText(A3)

Then A4 displays: Eight Hundred

'-------Start of Code---------
Option Explicit

'******************************************
'* NumsToWords() function *
'* Programmer: Ron Coderre *
'* Created on: 26-JUN-2007 *
'******************************************
Public Function NumsToWords( _
NumSource As Currency) _
As String

Dim Words As String ' Used to build the word phrase
Dim WIPnum As String ' Orig number formatted as 000000000000000.00
Dim LU_NumList() ' Array of numbers to match during the process
Dim LU_NumText() ' Text values associated with LU_NumList values
Dim iMisc As Integer ' Container for interim calculations
Dim iCtr As Integer ' Counter variable
Dim LU_Denom() ' Array of groups (Trillion, Billion, etc)

LU_NumList = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, _
11, 12, 13, 14, 15, 16, 17, 18, 19, _
20, 30, 40, 50, 60, 70, 80, 90)

LU_NumText = Array("", " One", " Two", " Three", " Four", " Five", _
" Six", " Seven", " Eight", " Nine", " Ten", " Eleven", _
" Twelve", " Thirteen", " Fourteen", " Fifteen", " Sixteen", _
" Seventeen", " Eighteen", " Nineteen", " Twenty", " Thirty", _
" Forty", " Fifty", " Sixty", " Seventy", " Eighty", " Ninety")

LU_Denom = Array(" Trillion", " Billion", " Million", " Thousand", "", "")

WIPnum = Replace(Format(NumSource, "000000000000000.00;KillFlow"), ".", "0")

'Pull successive WIPnum triads and assign word values
For iCtr = 0 To 5
iMisc = CInt(Mid(WIPnum, (1 + iCtr * 3), 3))

If Int(iMisc / 100) 0 Then
Words = Words & LU_NumText(Int(iMisc / 100)) & " Hundred"
End If

'Set the tens and ones phrase
If (iMisc Mod 100) 19 Then
Words = Words _
& LU_NumText(Int((iMisc Mod 100) / 10) + 18) _
& LU_NumText(iMisc Mod 10)
Else
Words = Words & LU_NumText(iMisc Mod 100)
End If

If iMisc 0 Then Words = Words & LU_Denom(iCtr)

If iCtr = 4 Then ' Done with whole nums
Words = Words & " " & MajorCurrency
If Int(NumSource) = 0 Then Words = "None"
End If
Next iCtr

NumsToWords = Trim(Words)
End Function
'-------End of Code---------


Is that something you can work with?

***********
Regards,
Ron

XL2002, WinXP


"bkbooker" wrote:

I need to display numbers as words in a legal document so I need to convert a
numbers to words

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2
Default Can you convert numbers to words - 800 as eight hundred

I tried it but wasn't succesful.
I get an error message #value in the cell.
I copied your code into a module.
(I first used NumsToText, but then realized in the code it is NumsToWords)
After closing out of VBA, I entered the formula =NumsToWords(I4) using my
cell reference.
Once entered, it takes me to VBA, which indicates I have a compile error,
variable not defined; "Major Currency" near the end of the code is highlighted

Thanks for the help


"Ron Coderre" wrote:

See if this helps...

I altered a function I wrote:

Paste the below VBA code into a general module
€¢ Hold [Alt] and press [F11]€¦..to view the visual basic editor
€¢ Select the workbook you want to use the function in
€¢ From the main menu: <insert<module
€¢ Copy the below code and paste it into the blank module

Now use the NumsToWords() function to convert numbers to a word phrase.
Example:
A3: 800
A4: =NumsToText(A3)

Then A4 displays: Eight Hundred

'-------Start of Code---------
Option Explicit

'******************************************
'* NumsToWords() function *
'* Programmer: Ron Coderre *
'* Created on: 26-JUN-2007 *
'******************************************
Public Function NumsToWords( _
NumSource As Currency) _
As String

Dim Words As String ' Used to build the word phrase
Dim WIPnum As String ' Orig number formatted as 000000000000000.00
Dim LU_NumList() ' Array of numbers to match during the process
Dim LU_NumText() ' Text values associated with LU_NumList values
Dim iMisc As Integer ' Container for interim calculations
Dim iCtr As Integer ' Counter variable
Dim LU_Denom() ' Array of groups (Trillion, Billion, etc)

LU_NumList = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, _
11, 12, 13, 14, 15, 16, 17, 18, 19, _
20, 30, 40, 50, 60, 70, 80, 90)

LU_NumText = Array("", " One", " Two", " Three", " Four", " Five", _
" Six", " Seven", " Eight", " Nine", " Ten", " Eleven", _
" Twelve", " Thirteen", " Fourteen", " Fifteen", " Sixteen", _
" Seventeen", " Eighteen", " Nineteen", " Twenty", " Thirty", _
" Forty", " Fifty", " Sixty", " Seventy", " Eighty", " Ninety")

LU_Denom = Array(" Trillion", " Billion", " Million", " Thousand", "", "")

WIPnum = Replace(Format(NumSource, "000000000000000.00;KillFlow"), ".", "0")

'Pull successive WIPnum triads and assign word values
For iCtr = 0 To 5
iMisc = CInt(Mid(WIPnum, (1 + iCtr * 3), 3))

If Int(iMisc / 100) 0 Then
Words = Words & LU_NumText(Int(iMisc / 100)) & " Hundred"
End If

'Set the tens and ones phrase
If (iMisc Mod 100) 19 Then
Words = Words _
& LU_NumText(Int((iMisc Mod 100) / 10) + 18) _
& LU_NumText(iMisc Mod 10)
Else
Words = Words & LU_NumText(iMisc Mod 100)
End If

If iMisc 0 Then Words = Words & LU_Denom(iCtr)

If iCtr = 4 Then ' Done with whole nums
Words = Words & " " & MajorCurrency
If Int(NumSource) = 0 Then Words = "None"
End If
Next iCtr

NumsToWords = Trim(Words)
End Function
'-------End of Code---------


Is that something you can work with?

***********
Regards,
Ron

XL2002, WinXP


"bkbooker" wrote:

I need to display numbers as words in a legal document so I need to convert a
numbers to words

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 698
Default Can you convert numbers to words - 800 as eight hundred

Awww...now, see! That's what I get for hurrying.

This works:

'-------Start of Code---------
Option Explicit

'******************************************
'* NumsToWords() function *
'* Programmer: Ron Coderre *
'* Created on: 26-JUN-2007 *
'******************************************
Public Function NumsToWords( _
NumSource As Currency) _
As String

Dim Words As String ' Used to build the word phrase
Dim WIPnum As String ' Orig number formatted as 000000000000000.00
Dim LU_NumList() ' Array of numbers to match during the process
Dim LU_NumText() ' Text values associated with LU_NumList values
Dim iMisc As Integer ' Container for interim calculations
Dim iCtr As Integer ' Counter variable
Dim LU_Denom() ' Array of groups (Trillion, Billion, etc)

LU_NumList = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, _
11, 12, 13, 14, 15, 16, 17, 18, 19, _
20, 30, 40, 50, 60, 70, 80, 90)

LU_NumText = Array("", " One", " Two", " Three", " Four", " Five", _
" Six", " Seven", " Eight", " Nine", " Ten", " Eleven", _
" Twelve", " Thirteen", " Fourteen", " Fifteen", " Sixteen", _
" Seventeen", " Eighteen", " Nineteen", " Twenty", " Thirty", _
" Forty", " Fifty", " Sixty", " Seventy", " Eighty", " Ninety")

LU_Denom = Array(" Trillion", " Billion", " Million", " Thousand", "", "")

WIPnum = Replace(Format(NumSource, "000000000000000.00;KillFlow"), ".", "0")

'Pull successive WIPnum triads and assign word values
For iCtr = 0 To 5
iMisc = CInt(Mid(WIPnum, (1 + iCtr * 3), 3))

If Int(iMisc / 100) 0 Then
Words = Words & LU_NumText(Int(iMisc / 100)) & " Hundred"
End If

'Set the tens and ones phrase
If (iMisc Mod 100) 19 Then
Words = Words _
& LU_NumText(Int((iMisc Mod 100) / 10) + 18) _
& LU_NumText(iMisc Mod 10)
Else
Words = Words & LU_NumText(iMisc Mod 100)
End If

If iMisc 0 Then Words = Words & LU_Denom(iCtr)

If iCtr = 4 Then ' Done with whole nums
Words = Words
If Int(NumSource) = 0 Then Words = "Zero"
End If
Next iCtr

NumsToWords = Trim(Words)
End Function
'-------End of Code---------

Does that help?

BTW....What exactly do you want to do with the number text? There may be a
better or more customized approach to take.

***********
Regards,
Ron

XL2002, WinXP


"bkbooker" wrote:

I tried it but wasn't succesful.
I get an error message #value in the cell.
I copied your code into a module.
(I first used NumsToText, but then realized in the code it is NumsToWords)
After closing out of VBA, I entered the formula =NumsToWords(I4) using my
cell reference.
Once entered, it takes me to VBA, which indicates I have a compile error,
variable not defined; "Major Currency" near the end of the code is highlighted

Thanks for the help


"Ron Coderre" wrote:

See if this helps...

I altered a function I wrote:

Paste the below VBA code into a general module
€¢ Hold [Alt] and press [F11]€¦..to view the visual basic editor
€¢ Select the workbook you want to use the function in
€¢ From the main menu: <insert<module
€¢ Copy the below code and paste it into the blank module

Now use the NumsToWords() function to convert numbers to a word phrase.
Example:
A3: 800
A4: =NumsToText(A3)

Then A4 displays: Eight Hundred

'-------Start of Code---------
Option Explicit

'******************************************
'* NumsToWords() function *
'* Programmer: Ron Coderre *
'* Created on: 26-JUN-2007 *
'******************************************
Public Function NumsToWords( _
NumSource As Currency) _
As String

Dim Words As String ' Used to build the word phrase
Dim WIPnum As String ' Orig number formatted as 000000000000000.00
Dim LU_NumList() ' Array of numbers to match during the process
Dim LU_NumText() ' Text values associated with LU_NumList values
Dim iMisc As Integer ' Container for interim calculations
Dim iCtr As Integer ' Counter variable
Dim LU_Denom() ' Array of groups (Trillion, Billion, etc)

LU_NumList = Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, _
11, 12, 13, 14, 15, 16, 17, 18, 19, _
20, 30, 40, 50, 60, 70, 80, 90)

LU_NumText = Array("", " One", " Two", " Three", " Four", " Five", _
" Six", " Seven", " Eight", " Nine", " Ten", " Eleven", _
" Twelve", " Thirteen", " Fourteen", " Fifteen", " Sixteen", _
" Seventeen", " Eighteen", " Nineteen", " Twenty", " Thirty", _
" Forty", " Fifty", " Sixty", " Seventy", " Eighty", " Ninety")

LU_Denom = Array(" Trillion", " Billion", " Million", " Thousand", "", "")

WIPnum = Replace(Format(NumSource, "000000000000000.00;KillFlow"), ".", "0")

'Pull successive WIPnum triads and assign word values
For iCtr = 0 To 5
iMisc = CInt(Mid(WIPnum, (1 + iCtr * 3), 3))

If Int(iMisc / 100) 0 Then
Words = Words & LU_NumText(Int(iMisc / 100)) & " Hundred"
End If

'Set the tens and ones phrase
If (iMisc Mod 100) 19 Then
Words = Words _
& LU_NumText(Int((iMisc Mod 100) / 10) + 18) _
& LU_NumText(iMisc Mod 10)
Else
Words = Words & LU_NumText(iMisc Mod 100)
End If

If iMisc 0 Then Words = Words & LU_Denom(iCtr)

If iCtr = 4 Then ' Done with whole nums
Words = Words & " " & MajorCurrency
If Int(NumSource) = 0 Then Words = "None"
End If
Next iCtr

NumsToWords = Trim(Words)
End Function
'-------End of Code---------


Is that something you can work with?

***********
Regards,
Ron

XL2002, WinXP


"bkbooker" wrote:

I need to display numbers as words in a legal document so I need to convert a
numbers to words

Reply
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
convert number like(852) to words like(eight hundred fifty two) SHAHID Excel Worksheet Functions 1 March 10th 07 03:34 PM
how to convert numbers into words jigesh Excel Worksheet Functions 1 December 8th 06 03:02 AM
how do i convert numbers in figures into words? Deepak Gupta Excel Discussion (Misc queries) 1 November 16th 05 05:18 AM
convert numbers to words prags Excel Worksheet Functions 2 July 4th 05 09:52 PM
how do i convert numbers to words MazenBy Excel Worksheet Functions 2 November 16th 04 05:28 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"