简体   繁体   English

excel udf 调用次数过多

[英]excel udf being called too many times

I have a excel function defined in a module which is called a total of two times as a worksheet functon.我在一个模块中定义了一个 excel function 作为工作表函数总共调用了两次。 However when I do a shift+f9 and place a breakpoint on the function, i noticed that its getting called more than twice, around 5 times.但是,当我执行 shift+f9 并在 function 上放置一个断点时,我注意到它被调用了两次以上,大约 5 次。 This function however is not being called anywhere else, both programmatically or in any worksheet except for the two cells i mentioned above.然而,除了我上面提到的两个单元格之外,这个 function 没有在其他任何地方被调用,无论是以编程方式还是在任何工作表中。

Furthermore, when I look at the call stack when execution hits my function, it shows just my function being the top level call.此外,当执行命中我的 function 时查看调用堆栈时,它显示只有我的 function 是顶级调用。 Any help regarding what may be causing this?关于可能导致此问题的任何帮助? Thanks.谢谢。

There are many possible reasons for this but probably the most likely is the UDF being called with uncalculated cells: 这有很多可能的原因,但最可能的原因是使用未计算的单元格调用UDF:
see http://www.decisionmodels.com/calcsecretsj.htm for details 有关详细信息,请参阅http://www.decisionmodels.com/calcsecretsj.htm

Possibly it could be position related.可能与 position 相关。 I was experiencing same thing with my UDF我的 UDF 遇到了同样的事情

The source range was below my udf cell.源范围低于我的 udf 单元格。 So Excel was calculating first the udf (with a few empty values from the uncalculated source range) and then again when the range was calculated and propagated to dependant cells (now with right values).因此 Excel 首先计算 udf(使用未计算的源范围中的一些空值),然后在计算范围并将其传播到相关单元格(现在具有正确的值)时再次计算。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM