I am making my first VBA program and trying to run the following function. The function checks a specific named range for the first row which does not have a value greater t
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
True, I had the same (in Excel 2010) and when I migrated to Excel 2016 , the function prototype was shown, but when I completed the function, the #NAME error was shown with a pop-up... so the code was never triggered.
It turned out I had a Macro of the same name as a Sub or UDF function ! I renamed the Macro, and then it worked
Cheers
Check "Trust access to the VBA project object model" in Macro settings from Macros security
You are getting that error because you have a module with the same name as the function.
Change that name to say find_Purchase
and everything will be fine :) See the image below...
One reason for this problem is security restrictions.. I had this problem and I activate "Enable all macros" from security center, and the problem solved
In addition to checking some of the above mentioned items, you might need to specify the filename where the custom function is actually defined, e.g. cell content =XLstart.xlsm!myCustomFunc(Arg1,Arg2) where myCustomFunc is defined in the startup file XLstart.xlsm.
Following the Excel help for "Correct a #NAME? error":
In the formula bar, select the [suspect] function name. In the Name Box (to the left of the formula bar), click the arrow and then select a [user-defined] function from the list that Excel suggests.
This will add the filename per the above format.
MS 2010, Windows 10.