How to call VBA function from Excel cells (2010)?

前端 未结 9 1787
暖寄归人
暖寄归人 2020-11-29 06:11

I defined a few functions in a workbook using VBA, and then expected to be able to use them in a cell formula - but Excel does not recognise the function. I just get #NAME?<

9条回答
  •  执笔经年
    2020-11-29 06:58

    I opened Excel, opened the code editor (Alt+F11), selected the new workbook, inserted a new Module, typed

    Function Decrement(i As Integer) As Integer
      Decrement = i - 1
    End Function
    

    then went back to my workbook and in A1 typed =Decrement(2) and hit Enter, and it worked. Decrement showed up in the drop-down list of functions as I typed =Decr... It was recognized, and it worked. I didn't even have to save the workbook.

    I know this isn't exactly an answer to your question, but it's the recipe I had luck with.

提交回复
热议问题