Data Tools · VBA

Number to Words (SpellNumber)

Custom function to spell a number in English words — great for invoices.

download.bas (ES) download.bas (EN)
' Converts a number to English words. Usage: =SpellNumber(1234)
Function SpellNumber(ByVal n As Double) As String
    Dim groups As Variant, parts As String, idx As Long, num As Long, chunk As Long
    groups = Array("", " Thousand", " Million", " Billion")
    num = Int(n)
    If num = 0 Then SpellNumber = "Zero": Exit Function

    idx = 0
    Do While num > 0
        chunk = num Mod 1000
        If chunk > 0 Then parts = ThreeDigits(chunk) & groups(idx) & " " & parts
        num = num \ 1000
        idx = idx + 1
    Loop
    SpellNumber = Trim(parts)
End Function

Private Function ThreeDigits(ByVal n As Long) As String
    Dim ones As Variant, teens As Variant, tens As Variant, s As String
    ones = Array("", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine")
    teens = Array("Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen")
    tens = Array("", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety")
    If n >= 100 Then
        s = ones(n \ 100) & " Hundred "
        n = n Mod 100
    End If
    If n >= 20 Then
        s = s & tens(n \ 10) & " "
        n = n Mod 10
    ElseIf n >= 10 Then
        s = s & teens(n - 10) & " "
        n = 0
    End If
    If n > 0 Then s = s & ones(n) & " "
    ThreeDigits = Trim(s)
End Function

Free to use and modify · ExcelBot — excelempowers.com

Adds a =SpellNumber(value) worksheet function that converts a number into English words.

How to install:

  1. Open your workbook and press Alt + F11 to open the VBA editor.
  2. Choose Insert ▸ Module and paste the code (or File ▸ Import File for the .bas).
  3. Press F5 to run, or run it from Developer ▸ Macros.
  4. Save your file as .xlsm (macro-enabled) to keep the macro.

No VBA? In ExcelBot you can do the same thing by just asking the AI in plain language.

spell number amount in words invoice número a letras factura
Rather not use VBA?

In ExcelBot you get the same result by asking the AI in plain language — no macros needed.

Try ExcelBot free Browse more macros

Related macros