Sub Num2Text()
'select the cell with the formula in
Dim c As Range
For Each c In Selection
AmountWord = ""
FracString = ""
OrigNum = c.Value
If InStr(1, OrigNum, ".") > 0 Then
Num = Left(OrigNum, InStr(1, OrigNum, ".") - 1)
FracString = Fraction(Right(OrigNum, Len(OrigNum) - InStr(1, OrigNum, ".")))
Else
Num = OrigNum
FacString = ""
End If
Do
If ((Len(Num) + 1) Mod 3) = 0 Then
HeadNum = Mid(Num, 1, 2)
TailLen = Len(Num) - 2
AmountWord = AmountWord & " " & HeadWord(HeadNum)
If HeadNum > 10 And HeadNum < 20 Then
Num = Right(Num, Len(Num) - 2)
AmountWord = AmountWord & " " & TailWord(TailLen)
Else
Num = Mid(Num, 2, Len(Num) - 1)
End If
Else
HeadNum = Mid(Num, 1, 1)
TailLen = Len(Num) - 1
AmountWord = AmountWord & " " & HeadWord(HeadNum) & " " & TailWord(TailLen)
'Num = Mid(Num, 2, Len(Num) - 1)
If Len(Num) > 1 Then
Num = Mid(Num, 2, Len(Num) - 1)
Else
Exit Do
End If
End If
Loop Until Len(Num) = 0
c.Value = AmountWord & " " & FracString
Next c
End Sub
Function Fraction(RemainNum) As String
Fraction = Round(RemainNum, 2) & "/100"
End Function
Function TailWord(TailLen) As String
Select Case TailLen
Case 7: TailWord = "Hundred"
Case 6: TailWord = "Million"
Case 5: TailWord = "Hundred"
Case 4: TailWord = "Thousand"
Case 3: TailWord = "Thousand"
Case 2: TailWord = "Hundred"
End Select
End Function
Function HeadWord(Num) As String
Select Case Num
Case 90 To 99: HeadWord = "Ninety"
Case 80 To 89: HeadWord = "Eighty"
Case 70 To 79: HeadWord = "Seventy"
Case 60 To 69: HeadWord = "Sixty"
Case 50 To 59: HeadWord = "Fifty"
Case 40 To 49: HeadWord = "Fourty"
Case 30 To 39: HeadWord = "Thirty"
Case 20 To 29: HeadWord = "Twenty"
Case 19: HeadWord = "Nineteen"
Case 18: HeadWord = "Eightteen"
Case 17: HeadWord = "Seventeen"
Case 16: HeadWord = "Sixteen"
Case 15: HeadWord = "Fifteen"
Case 14: HeadWord = "Fourteen"
Case 13: HeadWord = "Thirteen"
Case 12: HeadWord = "Twelve"
Case 11: HeadWord = "Eleven"
Case 10: HeadWord = "Ten"
Case 9: HeadWord = "Nine"
Case 8: HeadWord = "Eight"
Case 7: HeadWord = "Seven"
Case 6: HeadWord = "Six"
Case 5: HeadWord = "Five"
Case 4: HeadWord = "Four"
Case 3: HeadWord = "Three"
Case 2: HeadWord = "Two"
Case 1: HeadWord = "One"
End Select
End Function