Readding Numerical value to ext

H

Hoang Han

How do I cant to reading a numerical value of the cell to
text
Ex: A1 : $123
A2 : $123.50
A3 : $1,100.00
A4 : $109,100.50

The results will be display on B column is:
B1 : One hundred and twenty three dolars
B2 : One hundred and twenty three dolars and fifty
cents
B3 : One thousand and one hundred Dolars
B4 : One hundred and nine thousand and one hundred
dolars and fifty cents
 
G

Guest

You need a user defined function to do this. Go to the VBE and insert a new module, then copy and paste the following from "Option explicit" to "End Function

Courtesy of Dale Watson

Option Explici

'===============
' Main Functio
'===============
Function SpellNumber(ByVal MyNumber
Dim Dollars, Cents, Tem
Dim DecimalPlace, Coun

ReDim Place(9) As Strin
Place(2) = " Thousand
Place(3) = " Million
Place(4) = " Billion
Place(5) = " Trillion

'String representation of numbe
MyNumber = Trim(Str(MyNumber)

'Position of decimal place - 0 if non
DecimalPlace = InStr(MyNumber, "."
'Converts cents and sets MyNumber to dollar amoun
If DecimalPlace > 0 The
Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2)
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1)
End I

Count =
Do While MyNumber <> "
Temp = GetHundreds(Right(MyNumber, 3)
If Temp <> "" Then Dollars = Temp & Place(Count) & Dollar
If Len(MyNumber) > 3 The
MyNumber = Left(MyNumber, Len(MyNumber) - 3
Els
MyNumber = "
End I
Count = Count +
Loo

Select Case Dollar
Case "
Dollars = "No Dollars
Case "One
Dollars = "One Dollar
Case Els
Dollars = Dollars & " Dollars
End Selec

Select Case Cent
Case "
Cents = " and No Cents
Case "One
Cents = " and One Cent
Case Els
Cents = " and " & Cents & " Cents
End Selec

SpellNumber = Dollars & Cent
End Functio

'==========================================
' Converts a number from 100-999 into tex
'==========================================
Function GetHundreds(ByVal MyNumber
Dim Result As Strin

If Val(MyNumber) = 0 Then Exit Functio
MyNumber = Right("000" & MyNumber, 3

'Converts to hundreds plac
If Mid(MyNumber, 1, 1) <> "0" The
Result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred
End I

'Converts to tens and ones plac
If Mid(MyNumber, 2, 1) <> "0" The
Result = Result & GetTens(Mid(MyNumber, 2)
Els
Result = Result & GetDigit(Mid(MyNumber, 3)
End I

GetHundreds = Resul
End Functio

'==========================================
' Converts number from 10 to 99 into tex
'==========================================
Function GetTens(TensText
Dim Result As Strin

Result = "" 'null out temporary function value
If Val(Left(TensText, 1)) = 1 Then 'if value between 10-1
Select Case Val(TensText
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 Els
End Selec
Else 'if value between 20-9
Select Case Val(Left(TensText, 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 Els
End Selec
Result = Result & GetDigit
(Right(TensText, 1)) 'get ones plac
End I
GetTens = Resul
End Functio

'==========================================
' Converts number from 1 to 9 into tex
'==========================================
Function GetDigit(Digit
Select Case Val(Digit
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

enter
=spellnumber(A1)
where A1 is where the numerical value is
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top