简体   繁体   English

VBA自动筛选器隐藏单元格上的interior.colorindex使用#VALUE结束功能

[英]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.

相关问题 在用户函数中指定 .Interior.ColorIndex 时出现 VBA 错误 - VBA errors when you specify .Interior.ColorIndex in user function 单元格的.Interior.ColorIndex值不同于可见值 - Cell's .Interior.ColorIndex Value Different From What Is Visible Exce VBA Interior.ColorIndex增加文件大小 - Exce VBA Interior.ColorIndex increase file size 从.Interior.ColorIndex转换为颜色名称-VBA - Convert from .Interior.ColorIndex to Color name - VBA Excel vba .Interior.ColorIndex无法正常工作 - Excel vba .Interior.ColorIndex doesn't work properly Excel 2013中的#VALUE错误设置Interior.ColorIndex属性 - #VALUE error setting Interior.ColorIndex property in Excel 2013 VBA:使用数组搜索动态数据集条件并基于interior.colorindex进行复制 - VBA: Using an array to search dynamic dataset conditions and copy based on interior.colorindex Excel VBA —三个连续的单元格具有相同的interior.colorindex,但是这三个单元格的范围返回不同的颜色 - Excel VBA — three consecutive cells have the same interior.colorindex, but the range of these three cells returns different colors 有没有办法将整数值的数组传递给interior.colorindex - is there a way to pass an array of integer values to interior.colorindex 两种不同的内部单元格颜色给我相同的colorIndex VBA - Two different interior cell color give me the same colorIndex VBA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM