```
Option Explicit
'Main Function
Function SpellOrdinal(ByVal MyNumber)
Dim OrdinalNum, Temp
Dim Count
ReDim Place(9) As String
Place(2) = " Thousand "
Place(3) = " Million "
Place(4) = " Billion "
Place(5) = " Trillion "
' String representation of amount.
MyNumber = Trim(Str(MyNumber))
' Position of decimal place 0 if none.
Count = 1
Do While MyNumber <> ""
Temp = GetHundreds(Right(MyNumber, 3), Count = 1)
If Temp <> "" Then OrdinalNum = Temp & Place(Count) & OrdinalNum
If Len(MyNumber) > 3 Then
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
Else
MyNumber = ""
End If
Count = Count + 1
Loop
SpellOrdinal = Trim(Replace(OrdinalNum, " th", "th"))
End Function
' Converts a number from 100-999 into text
Function GetHundreds(ByVal MyNumber, Optional ForceOrdinal As Boolean = False)
Dim Result As String
If Val(MyNumber) = 0 And Not ForceOrdinal Then Exit Function
MyNumber = Right("000" & MyNumber, 3)
' Convert the hundreds place.
If Mid(MyNumber, 1, 1) <> "0" Then
Result = GetDigit(Mid(MyNumber, 1, 1)) & " Hundred "
End If
' Convert the tens and ones place.
If Mid(MyNumber, 2, 1) <> "0" Then
Result = Result & GetTens(Mid(MyNumber, 2), ForceOrdinal)
Else
If ForceOrdinal Then
Result = Result & GetOrdinalDigit(Mid(MyNumber, 3))
Else
Result = Result & GetDigit(Mid(MyNumber, 3))
End If
End If
If Result = "" And ForceOrdinal Then Result = "th"
GetHundreds = Result
End Function
' Converts a number from 10 to 99 into text.
Function GetTens(TensText As String, ForceOrdinal As Boolean)
Dim Result As String
Result = "" ' Null out the temporary function value.
If ForceOrdinal Then
Select Case Val(TensText)
Case 10: Result = "Tenth"
Case 11: Result = "Eleventh"
Case 12: Result = "Twelfth"
Case 13: Result = "Thirteenth"
Case 14: Result = "Fourteenth"
Case 15: Result = "Fifteenth"
Case 16: Result = "Sixteenth"
Case 17: Result = "Seventeenth"
Case 18: Result = "Eighteenth"
Case 19: Result = "Nineteenth"
Case 20: Result = "Twentieth"
Case 30: Result = "Thirtieth"
Case 40: Result = "Fortieth"
Case 50: Result = "Fiftieth"
Case 60: Result = "Sixtieth"
Case 70: Result = "Seventieth"
Case 80: Result = "Eightieth"
Case 90: Result = "Ninetieth"
Case Else
End Select
If Result = "" Then
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 Else
End Select
Result = Result & GetOrdinalDigit(Right(TensText, 1)) ' Retrieve ones place.
End If
Else
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 Else
End Select
If Result = "" Then
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 Else
End Select
If ForceOrdinal Then
Result = Result & GetOrdinalDigit(Right(TensText, 1)) ' Retrieve ones place.
Else
Result = Result & GetDigit(Right(TensText, 1)) ' Retrieve ones place.
End If
End If
End If
GetTens = Result
End Function
' Converts a number from 1 to 9 into text.
Function GetOrdinalDigit(Digit)
Select Case Val(Digit)
Case 1: GetOrdinalDigit = "First"
Case 2: GetOrdinalDigit = "Second"
Case 3: GetOrdinalDigit = "Third"
Case 4: GetOrdinalDigit = "Fourth"
Case 5: GetOrdinalDigit = "Fifth"
Case 6: GetOrdinalDigit = "Sixth"
Case 7: GetOrdinalDigit = "Seventh"
Case 8: GetOrdinalDigit = "Eighth"
Case 9: GetOrdinalDigit = "Ninth"
Case Else: GetOrdinalDigit = ""
End Select
End Function
' Converts a number from 1 to 9 into text.
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
```