![]() |
|
|||||||
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Hi all. I googled the code below and it is almost perfect to what i required. (credit to extendoffice.com)
However, currently it converts, for example : from 520,050 to Five Hundred Twenty Thousand Fifty What I actually want is in different condition, for example : from 520,005 to Five Hundred Twenty Thousand and Five from 520,050 to Five Hundred Twenty Thousand and Fifty from 520,500 to Five Hundred Twenty Thousand and Five Hundred from 520,000 to Five Hundred Thousand and Twenty Which part the codes below that I can amend from? Code:
Function NumberstoWords(ByVal pNumber)
'Updateby20140220
Dim Dollars
arr = Array("", "", " Thousand ", " Million ", " Billion ", " Trillion ")
pNumber = Trim(Str(pNumber))
xDecimal = InStr(pNumber, ".")
If xDecimal > 0 Then
pNumber = Trim(Left(pNumber, xDecimal - 1))
End If
xIndex = 1
Do While pNumber <> ""
xHundred = ""
xValue = Right(pNumber, 3)
If Val(xValue) <> 0 Then
xValue = Right("000" & xValue, 3)
If Mid(xValue, 1, 1) <> "0" Then
xHundred = GetDigit(Mid(xValue, 1, 1)) & " Hundred "
End If
If Mid(xValue, 2, 1) <> "0" Then
xHundred = xHundred & GetTens(Mid(xValue, 2))
Else
xHundred = xHundred & GetDigit(Mid(xValue, 3))
End If
End If
If xHundred <> "" Then
Dollars = xHundred & arr(xIndex) & Dollars
End If
If Len(pNumber) > 3 Then
pNumber = Left(pNumber, Len(pNumber) - 3)
Else
pNumber = ""
End If
xIndex = xIndex + 1
Loop
NumberstoWords = Dollars
End Function
Function GetTens(pTens)
Dim Result As String
Result = ""
If Val(Left(pTens, 1)) = 1 Then
Select Case Val(pTens)
Case 10: Result = "Ten"
Case 11: Result = "Eleven"
Case 12: Result = "Twelve"
Case 13: Result = "Thirteen"
Case 14: Result = "Fourteen"
Case 15: Result = "Fifteen"
Case 16: Result = "Sixteen"
Case 17: Result = "Seventeen"
Case 18: Result = "Eighteen"
Case 19: Result = "Nineteen"
Case Else
End Select
Else
Select Case Val(Left(pTens, 1))
Case 2: Result = "Twenty "
Case 3: Result = "Thirty "
Case 4: Result = "Forty "
Case 5: Result = "Fifty "
Case 6: Result = "Sixty "
Case 7: Result = "Seventy "
Case 8: Result = "Eighty "
Case 9: Result = "Ninety "
Case Else
End Select
Result = Result & GetDigit(Right(pTens, 1))
End If
GetTens = Result
End Function
Function GetDigit(pDigit)
Select Case Val(pDigit)
Case 1: GetDigit = "One"
Case 2: GetDigit = "Two"
Case 3: GetDigit = "Three"
Case 4: GetDigit = "Four"
Case 5: GetDigit = "Five"
Case 6: GetDigit = "Six"
Case 7: GetDigit = "Seven"
Case 8: GetDigit = "Eight"
Case 9: GetDigit = "Nine"
Case Else: GetDigit = ""
End Select
End Function
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Convert all equations to "Normal Text"
|
b0x4it | Word VBA | 16 | 02-14-2023 03:52 AM |
How to configure Word 10 so that when "enter" is pressed, the entire next line of text drops togethe
|
JKW | Word | 3 | 11-25-2015 04:55 PM |
| Spreadsheet with "CR" & "DB" in amount & number columns. | bfisher | Excel | 4 | 09-28-2015 07:03 AM |
Convert "Figure", "Figure", "Figure" to "Figure1", "Figure2", etc.
|
altjx | Word | 4 | 06-04-2013 05:29 AM |
Mailing: how to make the "page number" in Word is the same as "row number" in excel w
|
Jamal NUMAN | Word | 1 | 09-03-2011 11:37 AM |