calling excel worksheet function from excel cell

佐手、 提交于 2019-12-06 03:01:04

问题


I have a set of user defined vba functions that sit in an excel module, which are then called from an excel spreadsheet... everything has worked fine at this point.

I've been asked to move the vba from the module to the worksheet's code page. When I did this, I've found I can't call any of the functions from cells on the worksheet... the names simply don't show as existing. Is there a way to call worksheet functions from an excel cell? Also, is there any problem calling a worksheet function from a user defined function in another module or worksheet code behind?


EDIT:

I've found if I call by the sheetname.functionname, it throws an error message that includes "The name conflicts with an Excel built-in name or the name of another object in the workbook"... where if I use sheetname.anythingelse it just resolves to #NAME?

Does this mean excel worksheet functions cannot be called from a sheet?


回答1:


No. Functions in the worksheet object can't be called from the sheet as user-defined functions.

The Worksheet object is intended for responding to events that happen on a worksheet. You can't put user-defined functions there. User defined functions have to live in a Module.

If your user-defined function does live in a module, you won't have any problem calling it from code anywhere else... including in the worksheet "code-behind".




回答2:


You have to put the code in a standard module. Check this link.

http://www.cpearson.com/excel/writingfunctionsinvba.aspx



来源:https://stackoverflow.com/questions/4391229/calling-excel-worksheet-function-from-excel-cell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!