在 Excel 中应用自动过滤器时防止重新计算函数
Prevent Recalculating of Functions when applying autofilter in Excel
我正在使用 excel 2013。我有一个很大的 sheet,其中包含客户列表及其信息。当我将新客户添加到此 spreadsheet 时,它通过将 CustomerID 发布到我们的服务器来填充大部分信息,服务器 return 将客户信息存储在 Json 字符串中,然后对其进行解析。一个特定的函数 returns 所需的信息,即“=Json_get_email(Userid)”将 return 电子邮件地址。所有这些工作都非常好,并且对我公司的员工来说相对用户友好。
应用自动过滤器时会出现问题。即使其中没有函数是易变的,应用自动过滤器也会导致 spreadsheet 重新计算所有函数,而对客户或少数客户来说高效和快速的方法现在正在减慢 spreadsheet 就像疯了。
我想问问您是否有任何方法可以防止每次应用过滤器时都计算我的函数。
我最好的,
法比安
这样的事情会让你的 sheet 更快:
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
在使用相同参数值的调用之间缓存 return 电子邮件值应该没有问题。
这是我实施的解决方案。我想分享它,因为我看到很多人对 UDF 有同样的问题。
它并不完美,但速度更快,因为它避免了每次都连接到服务器并解析字符串。
我创建了一个 public 布尔值数组,索引为 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 提供的有用见解。
我正在使用 excel 2013。我有一个很大的 sheet,其中包含客户列表及其信息。当我将新客户添加到此 spreadsheet 时,它通过将 CustomerID 发布到我们的服务器来填充大部分信息,服务器 return 将客户信息存储在 Json 字符串中,然后对其进行解析。一个特定的函数 returns 所需的信息,即“=Json_get_email(Userid)”将 return 电子邮件地址。所有这些工作都非常好,并且对我公司的员工来说相对用户友好。
应用自动过滤器时会出现问题。即使其中没有函数是易变的,应用自动过滤器也会导致 spreadsheet 重新计算所有函数,而对客户或少数客户来说高效和快速的方法现在正在减慢 spreadsheet 就像疯了。
我想问问您是否有任何方法可以防止每次应用过滤器时都计算我的函数。
我最好的,
法比安
这样的事情会让你的 sheet 更快:
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
在使用相同参数值的调用之间缓存 return 电子邮件值应该没有问题。
这是我实施的解决方案。我想分享它,因为我看到很多人对 UDF 有同样的问题。
它并不完美,但速度更快,因为它避免了每次都连接到服务器并解析字符串。
我创建了一个 public 布尔值数组,索引为 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 提供的有用见解。