[英]interior.colorindex on VBA-autofilter hidden cell ends function with #VALUE
I'm getting a bizarre problem when using VBA to autofilter. 使用VBA自动过滤时,我遇到了一个奇怪的问题。 A cell in the top row (O1) contains a reference to a user-defined function to check the color of another cell (F2).
最上面一行(O1)中的一个单元格包含对用户定义函数的引用,以检查另一个单元格(F2)的颜色。 If I manually autofilter so the referenced cell F2 is hidden, the function works fine.
如果我手动自动过滤以使引用的单元格F2隐藏,则该功能可以正常工作。 If I have a VBA script performing the EXACT SAME FILTER (I used Macro Record to make sure), it returns a #VALUE!
如果我有一个执行完全相同过滤器的VBA脚本(我使用宏记录来确保),它将返回一个#VALUE! error.
错误。 Stepping through the code in debug mode, it hits the Interior.ColorIndex line - and silently exits the function (returning #VALUE!) without hitting the next Stop or generating a VBA error.
在调试模式下单步执行代码,它会到达Interior.ColorIndex行-并以静默方式退出该函数(返回#VALUE!),而无需达到下一个Stop或生成VBA错误。
Cell O1 contains: 单元格O1包含:
=stupidFunction()
VBA code: VBA代码:
Function stupidFunction()
Application.Volatile True
Calculate
Stop
stupidFunction = Range("F2").Interior.ColorIndex
Stop 'VBA autofilter never gets here, manual autofilter does!
End Function
Sub TestFilter()
'
' TestFilter Macro
'
'
ActiveSheet.Range("$A$1:$F$82").AutoFilter Field:=6, Criteria1:= _
"=*Approval*", Operator:=xlAnd
End Sub
Any idea what's going on? 知道发生了什么吗?
I can confirm the same behavior, but adding 我可以确认相同的行为,但是添加
ActiveSheet.Calculate
immediately after applying the VBA filtering fixes it (as does manually re-triggering the formula) 在应用VBA过滤后立即对其进行了修复(就像手动重新触发公式一样)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.