#NAME? error in Excel for VBA Function

I had the same issue myself. It turned out that I "Saved As..." another file and macros were not enabled for that file. No banner on the top appeared, but a #NAME? error was generated. I reopened the file, enabled macros, and the problem was resolved.


Make sure you have placed the function in a Standard Module. The error message means Excel can't find the function.


You are getting that error because you have a module with the same name as the function.

enter image description here

Change that name to say find_Purchase and everything will be fine :) See the image below...

enter image description here


When Excel opens an unkown workbook containing VBA-Code, it usually asks for macros to be enabled by the user (depending on the application settings).

If the user then enables the macros, all event-driven procedures will be started, such as auto_open or others.

Custom VBA Functions however require for a full recalculation of the workbook. Otherwise the functions return-value still is #NAME, as the calculation is only done directly after opening the workbook.

In order to work directly at the first time opening, one has to add the following line to the workbook_open event

'
' Workbook open event
Private Sub Workbook_Open()
    Application.CalculateFullRebuild
End Sub

Tags:

Excel

Vba