Fix the Excel #NAME? Error for a VBA User-Defined Function
Question details
Fix an Excel #NAME? error when a worksheet formula calls a VBA user-defined function.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A worksheet formula needs to call a VBA function, including a function with no arguments.
- Observed behavior
- Excel displays #NAME? when the function is called incorrectly or is unavailable to the worksheet.
Open the workbook in a desktop version of Excel that supports VBA. Identify the function name in the formula and make sure the workbook or add-in containing its code is available.
Check the VBA function call and make it available to Excel
Use these checks when Excel displays #NAME? instead of recognizing a VBA function in a worksheet formula.
Select the cell showing #NAME? and check the function name and parentheses in the formula bar. For a function with no arguments, enter =bScoresAreEntered() or =IF(bScoresAreEntered(),1,2).
Open the Visual Basic Editor from Developer > Visual Basic. In the project containing the function, confirm that it is declared Public, for example, Public Function bScoresAreEntered().
In the Visual Basic Editor, check that the function is in a standard module under Modules, rather than in a worksheet or ThisWorkbook code module. If needed, choose Insert > Module and move the function there.
If the function is stored in the workbook, choose File > Save As and select Excel Macro-Enabled Workbook (*.xlsm) as the file type.
Reopen the workbook and, if Excel displays a security warning, select Enable Content only if you trust the file and its source. Then select the formula cell and press Enter to recalculate it.

Work with Excel spreadsheets in WPS Office
WPS Office is a free, lightweight Office alternative with a familiar interface and support for common Excel formats, making it easy to move everyday spreadsheet work from Microsoft Office. VBA compatibility can vary, so test macro-dependent workbooks before switching.

Frequently Asked Questions
Why does my VBA function need parentheses in an Excel formula?
Parentheses identify the function call, even when it takes no arguments. In the formula bar, use =bScoresAreEntered() rather than leaving off the parentheses.
Where should I put a VBA function used by a worksheet?
In Developer > Visual Basic, place the Public function in a standard module under Modules. Choose Insert > Module if you need to create one.
Can I save a workbook with a VBA function as an XLSX file?
The XLSX format does not retain VBA code. Use File > Save As and select Excel Macro-Enabled Workbook (*.xlsm) when the function is stored in the workbook.
What should I do if Excel blocks the workbook's macros?
If a security warning appears when you open the workbook, select Enable Content only when you trust the file and its source. The VBA function cannot run if its macros remain blocked.




