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

前端 未结 9 1802
暖寄归人
暖寄归人 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:55

    XLSX file and XLSM files have nothing to do with it. Format plays the role when you save the file. (In XLSX, VBA code will be stripped while saving the file).

    The below code from http://office.microsoft.com/en-us/excel-help/creating-custom-functions-HA001111701.aspx works quite well inside a new module in my excel.

    Function Discount(quantity, price)
        If quantity >= 100 Then
            Discount = quantity * price * 0.1
        Else
            Discount = 0
        End If
        Discount = Application.Round(Discount, 2)
    End Function
    

    Given that I cannot see your code, can you try whether below function works for you too? If so, start modifying the below function so that it becomes your function (for example, first change the name and see if it works, and then change number of parameters and check if it works, and then change name of parameters).

提交回复
热议问题