Fix Excel #NAME? for a Public VBA Function
Question details
The user needs Excel to recognize a public VBA user-defined function in a worksheet formula.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A public user-defined function is stored in a worksheet code module and called from a worksheet cell.
- Observed behavior
- Excel displays #NAME? instead of evaluating the function.
Open the workbook and locate the function in its worksheet code module using Developer > Visual Basic. Confirm that you can edit the VBA project and that the function is declared Public.
Move the VBA function to a standard module
Use this solution when a public function is stored in a worksheet code module and Excel does not recognize it in a cell.
In Excel, select Developer > Visual Basic. In Project Explorer, expand the workbook and open the worksheet module containing the function.
Select the workbook's VBA project, then choose Insert > Module in the VBA editor.
Cut the complete Public Function procedure from the worksheet module and paste it into the new standard module. Include any helper procedures it depends on if they also need to be accessible there.
Choose Debug > Compile VBAProject in the VBA editor and correct any errors reported.
In Excel, choose File > Save As and save the workbook as an Excel Macro-Enabled Workbook (.xlsm) if necessary. In a worksheet cell, re-enter the function using its actual name and arguments, such as =MyFunction(A1).

Work with spreadsheets in WPS Office
WPS Office is a free, lightweight Office alternative with a familiar interface for opening and editing spreadsheets. It supports common Excel formats for easier migration, though VBA macro support and behavior may vary; use Excel to fix the VBA project described above.

Frequently Asked Questions
Why does Excel show #NAME? for my public VBA function?
Excel may not recognize the function as a worksheet function when it is stored in a worksheet code module. Move the Public Function procedure to a standard module through Developer > Visual Basic and Insert > Module.
How do I check whether the VBA code compiles?
Open Developer > Visual Basic, select the workbook's VBA project, and choose Debug > Compile VBAProject. Correct any errors the editor reports.
Which file format should I use for a VBA function?
Choose File > Save As and select Excel Macro-Enabled Workbook (.xlsm) to retain the VBA project.
What should I check if the function still does not work?
Check the function name and arguments in the cell formula, compile the project, and confirm that macros are enabled for the trusted workbook. Also check that any helper procedures used by the function are accessible from the standard module.




