Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 38
Default convert number to word

I wont to convert Currancy to Word.

Example : 567 = Five Hundrad Sisty Saven

Thanking you
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,316
Default convert number to word

The following 2 formulas are from an older version of the "VBA Developers
Handbook" by Ken Getz and Mike Gilbert. I think they'll get you pointed in
the correct direction:

Private Function dhHandleGroup(ByVal intValue As Integer) As String
' From "VBA Developer's Handbook"
' by Ken Getz and Mike Gilbert
' Copyright 1997; Sybex, Inc. All rights reserved.

' Called by dhNumToStr
Static varOnes As Variant
Static varTens As Variant
Dim strOut As String
Dim intDigit As Integer

If IsEmpty(varOnes) Then
varOnes = Array("", "One", "Two", "Three", "Four", "Five", _
"Six", "Seven", "Eight", "Nine", "Ten", _
"Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", _
"Sixteen", "Seventeen", "Eighteen", "Nineteen", "Twenty")
End If
If IsEmpty(varTens) Then
' Elements 0 and 1 in this array aren't used.
varTens = Array("", "", "Twenty", "Thirty", "Forty", _
"Fifty", "Sixty", "Seventy", "Eighty", "Ninety")
End If

' Get the hundreds digit, and then the rest.
intDigit = intValue \ 100
intValue = intValue Mod 100

' If there's a hundreds digit, add that now.
If intDigit 0 Then strOut = varOnes(intDigit) & " Hundred"

' Handle the tens and ones digits.
Select Case intValue
Case 1 To 20
strOut = strOut & varOnes(intValue)
Case 21 To 99
intDigit = intValue \ 10
intValue = intValue Mod 10
If intDigit 0 Then
strOut = strOut & " " & varTens(intDigit)
End If
If intValue 0 Then
strOut = strOut & "-" & varOnes(intValue)
End If
End Select

dhHandleGroup = strOut
End Function
Function dhNumToStr(ByVal varValue As Variant) As String
' From "VBA Developer's Handbook"
' by Ken Getz and Mike Gilbert
' Copyright 1997; Sybex, Inc. All rights reserved.

' Takes a number and converts it into text for writing
' checks. For example, 24.95 gets converted to
' Twenty-Four and 95/100

' In:
' varValue contains the number to be converted to text
' Out:
' Returns the string or an empty string on any error

On Error GoTo HandleErrors

Dim intTemp As Integer
Dim varNames As Variant
Dim lngDollars As Long
Dim intCents As Integer
Dim strOut As String
Dim strTemp As String
Dim intI As Integer

If Not IsNumeric(varValue) Then Exit Function

' 999,999,999.99 is the largest possible value.
If varValue 999999999.99 Then Exit Function
varNames = Array("", "Thousand", "Million")

varValue = Abs(varValue)
lngDollars = Int(varValue)
intCents = (varValue - lngDollars) * 100

If lngDollars 0 Then
' Loop through each set of three digits,
' first the hundreds, then thousands, and then
' millions.
Do
intTemp = lngDollars Mod 1000
lngDollars = Int(lngDollars / 1000)
' Prepend spelling of new triplet of digits to the
' existing output.
If intTemp < 0 Then
strOut = dhHandleGroup(intTemp) & " " & _
varNames(intI) & " " & strOut
End If
intI = intI + 1
Loop While lngDollars 0
' Handle the cents.
strOut = RTrim(strOut) & " and " & _
Format$(intCents, "00") & "/100"
End If

ExitHe
dhNumToStr = strOut
Exit Function

HandleErrors:
' Handle all errors by returning an empty string
strOut = ""
Resume ExitHere
End Function

--
Kevin Backmann


"ROHIT" wrote:

I wont to convert Currancy to Word.

Example : 567 = Five Hundrad Sisty Saven

Thanking you

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
Number in cell convert in word Rajiul Excel Worksheet Functions 2 October 5th 05 08:47 AM
convert a Word doc into an Excel doc. Tedb Excel Discussion (Misc queries) 1 July 28th 05 07:25 PM
can excel convert number into words (like 10 to ten)? nivedrajesh Excel Worksheet Functions 2 July 11th 05 01:06 PM
"Convert to Number" option disappearing Mike Excel Discussion (Misc queries) 2 June 10th 05 04:11 PM
How do i convert a number of seconds to a date/time? Margo Excel Worksheet Functions 2 January 5th 05 12:09 AM


All times are GMT +1. The time now is 07:49 AM.

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"