VBA & Macro Problems

Fix Excel #NAME? for a Public VBA Function

Khadija KhanKhadija Khan Nov 27, 2026 869 views

Question details

The user needs Excel to recognize a public VBA user-defined function in a worksheet formula.

Fix Excel #NAME? for a Public VBA Function
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the VBA editor

In Excel, select Developer > Visual Basic. In Project Explorer, expand the workbook and open the worksheet module containing the function.

2
Create a standard module

Select the workbook's VBA project, then choose Insert > Module in the VBA editor.

3
Move the function

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.

4
Compile the project

Choose Debug > Compile VBAProject in the VBA editor and correct any errors reported.

5
Save and test the formula

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).

Move the VBA function to a standard module
Enable trusted macros: If Excel displays a security warning when you reopen the workbook, enable macros only if you trust the file and its source.
Free Microsoft Office alternative

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.

Edit spreadsheet formulas in a familiar interfaceOpen and save Microsoft Excel formats such as .xlsxUse a free, lightweight Office alternativeMove between common Office document formats more easily
microsoft office alternative - wps office

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.