I noticed that my UDFs are recounted whenever I delete cells. This leads to huge delays when deleting entire columns, since UDF is called for each and every cell in which it is used. Therefore, if you use 1000 UDFS, then deleting a column or cell will call it 1000 times.
As an example, put the following UDF in the module, and then name it from the sheet several times with = HelloWorld ()
Function HelloWorld() HelloWorld = "HelloWorld" Debug.Print Now() End Function
Then delete the line. If your experience is similar to mine, you will see that it is called once for each use case.
Does anyone have any idea if this behavior can be stopped? I would also be wondering why it needs to be called. It seems like I'm wrong in the Excel dependency tree, but there might be a good reason.
Edit: after experimenting, I found more actions that run UDFS:
- Any change in the number of columns that a ListObject (i.e. an Excel spreadsheet) covers resize (but not rows). Even if the UDFs themselves are not in the corresponding ListObject or in any ListObject at all.
- Add new cells or columns anywhere in the sheet (but not in rows).
Please note that manual Calc mode is not an option on multiple fronts.
First of all, given that this is an application-level parameter, it simply poses too much risk that someone will use the output of any of the spreadsheets that they can open without realizing that they are in manual calculation mode.
Secondly, I donβt actually create a specific spreadsheet, but rather I am writing a book about how non-developers can use well-written off-the-shelf code, such as UDF, to do things that would otherwise be outside. Examples include dynamic concatenation or text splitting, or an exact match for the UDF binary search, which Charles Williams describes at https://fastexcel.wordpress.com/2011/07/22/developing-faster-lookups-part-2-how-to-build -a-faster-vba-lookup / (And yes, I give them a lot of warning that usually their own formula-based solution will be superior to UDF. But, as you will see from the stream I referenced above, carefully written functions may work well )
I do not know how users will use them.
In the absence of a software solution, it seems that I just have to point out in the book that users can experience a significant delay when adding or removing cells or resizing ListObjects if they use resource-intensive UDFS. Even if these UDFs are effectively written.