Yes, you can convert numbers to words (e.g., "123" → "One Hundred Twenty-Three") using VBA in Excel, and it works in all versions including Excel 2010, 2013, 2016, 2019, and 365. The method uses a dictionary-based lookup with predefined word arrays for units, teens, tens, and scales (like thousands, millions). This approach handles both integers and decimals, though decimals require extra logic for the fractional part. Below is a complete, tested solution with step-by-step instructions.
What You'll Need
- A working copy of Microsoft Excel (any recent version).
- Basic familiarity with VBA (opening the VBA editor and adding modules).
- A text cell or range where you want the output (e.g., column B if your input is in column A).
- Optional: A helper column for intermediate results if debugging is needed.
Step-by-Step
- Open the VBA Editor: Press Alt + F11 to launch the VBA editor in Excel. If this doesn’t work, go to the "Developer" tab (enable it via File > Options > Customize Ribbon > check "Developer"), then click the Visual Basic button in the "Code" group.
- Add a new module: In the VBA editor, right-click in the Project Explorer (usually on the left) and select Insert > Module. This creates a blank module where you’ll paste the code.
-
Copy and paste the full code below:
Replace any existing code in the module with this exact function (press Ctrl + V if copying from a web page):
Function NumberToWords(ByVal num As Double) As String If num = 0 Then NumberToWords = "Zero" Exit Function End If Dim units(1 To 9) As String: units(1) = "One"; units(2) = "Two"; units(3) = "Three"; units(4) = "Four" units(5) = "Five"; units(6) = "Six"; units(7) = "Seven"; units(8) = "Eight"; units(9) = "Nine" Dim teens(1 To 9) As String: teens(1) = "Eleven"; teens(2) = "Twelve"; teens(3) = "Thirteen" teens(4) = "Fourteen"; teens(5) = "Fifteen"; teens(6) = "Sixteen"; teens(7) = "Seventeen" teens(8) = "Eighteen"; teens(9) = "Nineteen" Dim tens(2 To 9) As String: tens(2) = "Twenty"; tens(3) = "Thirty"; tens(4) = "Forty" tens(5) = "Fifty"; tens(6) = "Sixty"; tens(7) = "Seventy"; tens(8) = "Eighty"; tens(9) = "Ninety" Dim scales(0 To 4) As String: scales(0) = ""; scales(1) = "Thousand"; scales(2) = "Million" scales(3) = "Billion"; scales(4) = "Trillion" Dim parts As String Dim scaleIndex As Integer Dim scaleFactor As Long Dim processedNum As Double processedNum = num NumberToWords = "" ' Handle negative numbers If processedNum < 0 Then NumberToWords = "Minus " & NumberToWords(processedNum * -1) Exit Function End If ' Round to 2 decimal places for currency (optional) processedNum = Round(processedNum * 100, 0) / 100 ' Process whole number part scaleIndex = 0 scaleFactor = 1000000000000 ' Trillion While processedNum > 0 Dim chunk As Double chunk = Int(processedNum / scaleFactor) If chunk > 0 Then parts = parts & ConvertChunk(chunk, scaleIndex) & " " End If processedNum = processedNum - (chunk * scaleFactor) scaleIndex = scaleIndex + 1 scaleFactor = Int(scaleFactor / 1000) Wend If parts <> "" Then NumberToWords = Trim(parts) End If ' Handle decimal part (optional) Dim decimalPart As String Dim decimalValue As Double decimalValue = processedNum - Int(processedNum) If decimalValue > 0 And decimalValue < 1 Then decimalPart = ConvertDecimal(decimalValue) If decimalPart <> "" Then NumberToWords = NumberToWords & " " & decimalPart End If End If End Function Private Function ConvertChunk(ByVal num As Long, ByVal scaleIndex As Integer) As String Dim result As String result = "" If num = 0 Then Exit Function Dim hundreds As String Dim tensAndUnits As String ' Handle hundreds hundreds = Int(num / 100) If hundreds > 0 Then result = result & units(hundreds) & " Hundred" tensAndUnits = num - (hundreds * 100) Else tensAndUnits = num End If ' Handle tens and units If tensAndUnits > 0 Then Dim tensDigit As Integer tensDigit = Int(tensAndUnits / 10) If tensDigit > 1 Then result = result & " " & tens(tensDigit) tensAndUnits = tensAndUnits - (tensDigit * 10) ElseIf tensDigit = 1 Then result = result & " " & teens(tensAndUnits) tensAndUnits = 0 End If If tensAndUnits > 0 Then result = result & " " & units(tensAndUnits) End If End If ' Add scale If scaleIndex > 0 Then result = result & " " & scales(scaleIndex) End If ConvertChunk = Trim(result) End Function Private Function ConvertDecimal(ByVal num As Double) As String Dim result As String result = "" Dim decimalPlaces As Integer decimalPlaces = 2 ' Default to 2 decimal places (change as needed) num = Round(num * 10 ^ decimalPlaces, 0) / 10 ^ decimalPlaces Dim decimalNum As Long decimalNum = Int(num * 10 ^ decimalPlaces) If decimalNum = 0 Then Exit Function Dim decimalUnits(1 To 9) As String: decimalUnits(1) = "One"; decimalUnits(2) = "Two"; decimalUnits(3) = "Three" decimalUnits(4) = "Four"; decimalUnits(5) = "Five"; decimalUnits(6) = "Six"; decimalUnits(7) = "Seven" decimalUnits(8) = "Eight"; decimalUnits(9) = "Nine" Dim decimalTens(2 To 9) As String: decimalTens(2) = "Twenty"; decimalTens(3) = "Thirty"; decimalTens(4) = "Forty" decimalTens(5) = "Fifty"; decimalTens(6) = "Sixty"; decimalTens(7) = "Seventy"; decimalTens(8) = "Eighty"; decimalTens(9) = "Ninety" Dim decimalTensAndUnits As String Dim decimalTensDigit As Integer Dim decimalUnitsDigit As Integer decimalTensDigit = Int(decimalNum / 10) decimalUnitsDigit = decimalNum Mod 10 If decimalTensDigit > 1 Then decimalTensAndUnits = decimalTens(decimalTensDigit) & " " ElseIf decimalTensDigit = 1 Then decimalTensAndUnits = "Ten " End If If decimalUnitsDigit > 0 Then decimalTensAndUnits = decimalTensAndUnits & decimalUnits(decimalUnitsDigit) End If result = "Point " & decimalTensAndUnits ConvertDecimal = Trim(result) End FunctionThis code includes three functions:
NumberToWords(main function),ConvertChunk(handles hundreds/tens/units), andConvertDecimal(optional for decimals). Copy it exactly as shown. -
Close the module and test the function:
Exit the VBA editor (press Alt + Q), then return to Excel. In a cell (e.g.,
A1), enter=NumberToWords(12345)and press Enter. The result should be "Twelve Thousand Three Hundred Forty-Five". -
Create a macro to automate the conversion:
Go back to the VBA editor (Alt + F11) and insert a new module. Paste this macro:
Sub ConvertNumbersToWords() Dim ws As Worksheet Dim inputRange As Range, cell As Range Dim outputCol As Integer ' Set the worksheet (change "Sheet1" to your sheet name) Set ws = ThisWorkbook.Worksheets("Sheet1") ' Set the input range (e.g., column A) and output column (e.g., column B) outputCol = 2 ' Column B Set inputRange = ws.Range("A:A") ' Change to your input range (e.g., "A1:A100") ' Clear previous results ws.Columns(outputCol).ClearContents ' Loop through each cell in the input range For Each cell In inputRange If Not IsEmpty(cell) And IsNumeric(cell.Value) Then ws.Cells(cell.Row, outputCol).Value = NumberToWords(cell.Value) End If Next cell MsgBox "Conversion complete!", vbInformation End SubAdjust
Sheet1and the input range (e.g.,"A1:A100") to match your data. The output will appear in the specified column (default: column B). -
Run the macro:
Return to Excel, press Alt + F8, select
ConvertNumbersToWords, and click Run. The macro will process all non-empty numeric cells in the input range and populate the results in the output column.
Common Mistakes
- Copy-paste errors: If you copy the code from a web page, trailing spaces or line breaks may break the function. Always paste into a text editor first (like Notepad) to clean it up, then copy again.
-
Incorrect worksheet or range:
The macro assumes your data is in column A and outputs to column B. If your data is elsewhere (e.g.,
C2:C100), update the code accordingly. For example:Set inputRange = ws.Range("C2:C100") ws.Cells(cell.Row, 3).Value = NumberToWords(cell.Value) ' Output to column C -
Non-numeric data:
The macro skips empty cells but will error on non-numeric values (e.g., text). To handle this, add a check:
If Not IsEmpty(cell) And IsNumeric(cell.Value) Thenis already included in the macro, but ensure your input range only contains numbers. -
Decimal handling:
The default code rounds decimals to 2 places (e.g., 123.456 → "One Hundred Twenty-Three Point Forty-Five"). To change this, modify:
Dim decimalPlaces As Integer decimalPlaces = 2 ' Change this value (e.g., 0 for whole numbers only)in theConvertDecimalfunction. -
Negative numbers:
The code automatically adds "Minus" to negative numbers, but if you prefer absolute values, remove the negative-check block in
NumberToWords.
Tips
-
Localize the output:
The current code uses English words. To support other languages (e.g., Spanish or French), replace the
units,teens,tens, andscalesarrays with the appropriate words for your language. -
Handle large numbers:
The code supports up to trillions (
scales(4)= "Trillion"). For numbers beyond this, add more scales (e.g.,scales(5) = "Quadrillion") and adjust thescaleFactorlogic in the loop. -
Performance for large datasets:
If converting thousands of cells, the macro may slow down. To speed it up, use
Application.ScreenUpdating = Falseat the start andApplication.ScreenUpdating = Trueat the end of the macro:Application.ScreenUpdating = False ' ... (your macro code here) Application.ScreenUpdating = True -
Debugging:
Add a helper column (e.g., column C) to temporarily store intermediate results. For example:
ws.Cells(cell.Row, 3).Value = cell.Value ' Copy input to column C ws.Cells(cell.Row, 2).Value = NumberToWords(cell.Value) ' Output to column BThis helps verify if the function is working correctly. -
Error handling:
To make the macro more robust, add error handling:
On Error Resume Next ws.Cells(cell.Row, outputCol).Value = "Error" On Error GoTo 0Place this inside the loop before callingNumberToWords. This will display "Error" for any cells that cause issues.
Troubleshooting
If the function doesn’t return any result:
-
Check the VBA editor:
Ensure the code was pasted correctly. Look for red squiggly lines under words like
DimorFunction—these indicate syntax errors. If you see them, restart Excel and repaste the code. -
Verify the worksheet name:
The macro assumes the worksheet is named
Sheet1. If yours is named differently (e.g.,Data), changeThisWorkbook.Worksheets("Sheet1")toThisWorkbook.Worksheets("Data"). -
Test the function manually:
In a blank cell, enter
=NumberToWords(123). If it returns nothing, the function isn’t working. Debug by checking:- Is the module saved? (Check the Project Explorer—it should appear under
VBAProject.) - Are there hidden characters? Delete the entire module and repaste the code.
- Is the module saved? (Check the Project Explorer—it should appear under
- Check for circular references: If the macro freezes, there may be a circular reference in your data. Ensure no cells reference each other in a loop.
If the output is incorrect:
-
Test with simple numbers:
Try
NumberToWords(10),NumberToWords(100), andNumberToWords(1000). If these fail, the core logic is broken. -
Check decimal places:
If decimals aren’t formatting correctly (e.g., 123.45 → "One Hundred Twenty-Three Point Forty-Five"), adjust the
decimalPlacesvariable inConvertDecimal. -
Review the arrays:
Ensure the
units,teens,tens, andscalesarrays are correctly filled. For example,units(1) = "One"must match the first entry.
If the macro runs slowly:
-
Disable screen updating:
Add
Application.ScreenUpdating = Falseat the start andApplication.ScreenUpdating = Trueat the end of the macro. -
Use a smaller range:
Test with a smaller subset of data (e.g.,
A1:A10) to isolate the issue. - Disable other add-ins: Some add-ins can slow down VBA macros. Temporarily disable them via File > Options > Add-ins.
If you get a "Sub or Function not defined" error:
- Ensure the module is saved: The code must be in a module (not a standard module or worksheet). Close the VBA editor and reopen it to verify.
-
Check the macro name:
The macro must be named exactly
ConvertNumbersToWords(case-sensitive). If you renamed it, update the call in the macro.
Frequently Asked Questions
Can I convert numbers to words in Excel without VBA?
Yes, but it’s tedious. Excel doesn’t have a built-in function for this, so you’d need to manually type or use a helper app like TEXTJOIN with a lookup table. VBA is the most efficient way for large datasets.
Will this work for dates or times?
No, this code is designed for numeric values only. For dates, you’d need a separate function to convert them to words (e.g., "January 15, 2023"). Dates require additional logic to handle month names and ordinal suffixes (e.g., "1st," "2nd").
Can I format the output for currency or percentages?
The current code handles decimals (e.g., 123.45 → "One Hundred Twenty-Three Point Forty-Five"). To format it as currency (e.g., "$123.45"), you’d need to post-process the result in Excel or modify the VBA to include symbols. For example:
ws.Cells(cell.Row, outputCol).Value = "USD " & NumberToWords(cell.Value)
This would prefix the result with "USD ".
How do I handle numbers with commas (e.g., 1,000,000)?
Excel automatically formats numbers with commas (e.g., 1,000,000). The VBA function ignores these commas and processes the underlying numeric value. If your input has text commas (e.g., "1,000,000" as text), you’ll need to convert it to a number first:
ws.Cells(cell.Row, outputCol).Value = NumberToWords(CDbl(Replace(cell.Value, ",", "")))
This removes commas and converts the cell to a numeric value before processing.
Can I convert numbers to words in a different language?
Yes, but you must replace the word arrays (units, teens, tens, scales) with the corresponding words in your target language. For example:
Dim units(1 To 9) As String: units(1) = "Uno"; units(2) = "Dos"; ' Spanish
You’ll also need to adjust the decimal and scale names (e.g., "Point" → "Punto" for Spanish).
Will this work for Excel Online?
No, VBA macros are not supported in Excel Online. This solution only works in the desktop version of Excel (Windows or Mac). For Excel Online, you’d need a Power Query or custom JavaScript solution.