#NAME? error in Excel for VBA Function

后端 未结 12 848
耶瑟儿~
耶瑟儿~ 2020-12-31 01:01

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

相关标签:
12条回答
  • 2020-12-31 01:28

    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
    
    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-12-31 01:32

    Check "Trust access to the VBA project object model" in Macro settings from Macros security

    0 讨论(0)
  • 2020-12-31 01:33

    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

    0 讨论(0)
  • 2020-12-31 01:35

    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

    0 讨论(0)
  • 2020-12-31 01:37

    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.

    0 讨论(0)
提交回复
热议问题