#NAME? error in Excel for VBA Function

后端 未结 12 999
耶瑟儿~
耶瑟儿~ 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条回答
  •  -上瘾入骨i
    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
    

提交回复
热议问题