在Excel中应用自动筛选时防止重新计算函数

我正在使用Excel 2013.我有一个大的表单,其中包含客户及其信息列表。 当我向该电子表格添加新客户时,通过将CustomerID发布到我们的服务器来填充大部分信息,服务器以Jsonstring的forms返回客户信息,然后parsing。 一个特定的函数返回所需的信息,即“= Json_get_email(Userid)”将返回电子邮件地址。 所有这些工作都非常好,对我公司的员工来说也是比较用户友好的。

应用自动filter时会出现问题。 即使没有任何function是挥发性的,使用自动filter会导致电子表格重新计算所有function,而对于客户或less数客户而言,有效和快速的function现在正在放慢电子表格的速度。

我正在转向您,以了解是否有任何方法可以防止每次应用filter时计算我的function。

我最好的,

法比恩

像这样的东西会使你的表快得多:

 Function Json_get_email(arg) Static dict As Object '<< persists between calls If dict is nothing then set dict = Createobject("scripting.dictionary") If not dict.exists(arg) Then 'have not seen this value of arg before '...get the return "email" value for 'arg' here dict.add arg, email End If Json_get_email = dict(arg) 'return the cached value End Function 

在使用相同参数值的调用之间caching返回电子邮件值应该没有问题。

这是我实施的解决scheme。 我想分享一下,因为我已经看到许多人与UDF有同样的问题。

它并不完美,但速度更快,因为它避免每次连接到服务器和parsingstring。

我创build了一个由User_ID索引的布尔公共数组,

 Public Names_in_List(100000000 To 104000000) As Boolean Function JSon_CustomerName2(UserID As String) As String If Names_in_List(UserID) = False Then 'The Function Has not yet been run for this ID '... Do whatever Names_in_List(UserID) = True 'Update the status Else JSon_CustomerName2 = Application.Caller.value 'Reuse the value that was in the cell. End If End Function 

和往常一样,我不得不为了速度而交换内存,但是布尔对于每个用户来说只有一个位。

非常感谢@Tim为您提供有益的见解。