开发者

calling excel worksheet function from excel cell

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 cod开发者_运维问答e 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?


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".


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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜