One Two Three Serial Number VBA Code For Excel


Function NumberToWords(ByVal Num As Long) As String

    Dim Ones As Variant
    Dim Tens As Variant
    Dim Result As String

    Ones = Array("", "One", "Two", "Three", "Four", _
    "Five", "Six", "Seven", "Eight", "Nine", _
    "Ten", "Eleven", "Twelve", "Thirteen", _
    "Fourteen", "Fifteen", "Sixteen", _
    "Seventeen", "Eighteen", "Nineteen")

    Tens = Array("", "", "Twenty", "Thirty", "Forty", _
    "Fifty", "Sixty", "Seventy", "Eighty", "Ninety")

    If Num < 0 Or Num > 1000 Then
        NumberToWords = "Out of Range"
        Exit Function
    End If

    If Num = 0 Then
        NumberToWords = "Zero"
        Exit Function
    End If

    If Num = 1000 Then
        NumberToWords = "One Thousand"
        Exit Function
    End If

    If Num >= 100 Then
        Result = Ones(Num \ 100) & " Hundred"
        Num = Num Mod 100
        If Num > 0 Then Result = Result & " "
    End If

    If Num >= 20 Then
        Result = Result & Tens(Num \ 10)
        Num = Num Mod 10
        If Num > 0 Then Result = Result & " "
    End If

    If Num > 0 Then
        Result = Result & Ones(Num)
    End If

    NumberToWords = Result

End Function

Leave a Comment

Prove your humanity: 8   +   4   =