Fix the Excel SpellNumber #NAME? Error and VBA Compile Errors
Question details
Correct the SpellNumber VBA function so Excel can convert numbers to words without a compile error or #NAME? result.

- 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.
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.
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.
In desktop Excel, select Developer > Visual Basic, then open the module containing SpellNumber. On Windows, you can also press Alt+F11.
Replace the incorrectly continued statement with this single line: Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & "00", 2)).
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.
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).

Check the SpellNumber function and macro settings
Use these checks if the code compiles but the worksheet still displays #NAME?.
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.

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.




