VBA & Macro Problems

Fix the Excel SpellNumber #NAME? Error and VBA Compile Errors

Amos GikundaAmos Gikunda Nov 22, 2026 870 views

Question details

Correct the SpellNumber VBA function so Excel can convert numbers to words without a compile error or #NAME? result.

Fix the Excel SpellNumber #NAME? Error and VBA Compile Errors
Product
Microsoft Excel
Device & OS
not provided
Scenario
Using the SpellNumber VBA function in a worksheet formula to convert a number to words.
Observed behavior
Excel returns #NAME?, or the VBA code fails to compile because a line-continuation character is formatted incorrectly.
Before you start

Open the workbook in desktop Excel and locate the SpellNumber code in the Visual Basic Editor. Make sure the workbook is saved in a macro-enabled format such as .xlsm.

Solution 1Recommended

Correct the VBA line-continuation syntax

Use this fix when Excel highlights a SpellNumber statement that contains a misplaced underscore.

A VBA line-continuation underscore must be preceded by a space and be the final character on the line. The rest of the statement must continue on the next line.

1
Open the VBA code

In desktop Excel, select Developer > Visual Basic, then open the module containing SpellNumber. On Windows, you can also press Alt+F11.

2
Fix the cents statement

Replace the incorrectly continued statement with this single line: Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2)).

3
Fix other misplaced underscores

For a statement such as Result = Result & GetDigit _(Right(TensText, 1)), remove the underscore and use: Result = Result & GetDigit(Right(TensText, 1)). Alternatively, place a space and underscore at the end of a line and continue the statement on the next line.

4
Compile and test

In the Visual Basic Editor, select Debug > Compile VBAProject and correct any remaining highlighted errors. Return to the worksheet and test a formula such as =SpellNumber(A1).

Correct the VBA line-continuation syntax
Keep helper functions: SpellNumber implementations may depend on helper functions such as GetTens and GetDigit. Keep the complete code together and resolve any missing-function errors reported during compilation.
Free Microsoft Office alternative

Work with Excel spreadsheets in WPS Office

WPS Office is a free, lightweight alternative with a familiar spreadsheet interface for opening and editing Excel files. It can help you move everyday spreadsheet work to WPS, but it does not repair Excel VBA compile errors.

Open and edit Microsoft Excel XLSX spreadsheetsUse a familiar spreadsheet interface for formulas and worksheet dataMove everyday spreadsheet work from Excel with compatible file formatsUse a free, lightweight office suite
microsoft office alternative - wps office

Frequently Asked Questions

Why does my SpellNumber formula show #NAME?

Excel may not recognize the function name or be able to run its VBA code. Check the spelling in the formula, confirm that SpellNumber is a public function in a standard module, and enable macros if you trust the workbook.

Where should the underscore go in a VBA continuation line?

Put a space before the underscore and make the underscore the last character on the line. Continue the statement on the next line, or remove the underscore and keep the statement on one line.

How do I find other errors in the SpellNumber code?

Open Developer > Visual Basic and select Debug > Compile VBAProject. Correct any highlighted errors, including missing helper functions, then compile again.

Can I save the SpellNumber code in an XLSX file?

Use File > Save As and choose Excel Macro-Enabled Workbook (.xlsm) to retain the VBA code. The XLSX format does not preserve VBA macros.