Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 多个条件的搜索表_Vba - Fatal编程技术网

Vba 多个条件的搜索表

Vba 多个条件的搜索表,vba,Vba,我有一个代码,它在我的工作表中搜索颜色索引为16的非隐藏单元格 但是,我想添加第三个标准:SpecialCells(xlCellTypeBlanks) 因此,仅当满足3个条件时,消息才会出现 感谢你的想法 谢谢首先,使用选项显式!这样可以防止将cl和c1混为一谈,就像您在代码中所做的那样!此外,最好的做法是使用缩进使代码更易于阅读 您可以使用应用程序来实现自己的愿望。Intersect: For Each c1 In ActiveSheet.UsedRange.SpecialCells(xlCe

我有一个代码,它在我的工作表中搜索颜色索引为16的非隐藏单元格

但是,我想添加第三个标准:
SpecialCells(xlCellTypeBlanks)

因此,仅当满足3个条件时,消息才会出现

感谢你的想法


谢谢

首先,使用
选项显式
!这样可以防止将
cl
c1
混为一谈,就像您在代码中所做的那样!此外,最好的做法是使用缩进使代码更易于阅读

您可以使用
应用程序来实现自己的愿望。Intersect

For Each c1 In ActiveSheet.UsedRange.SpecialCells(xlCellTypeVisible)
If cl.Interior.ColorIndex = 16 Then

MsgBox "Error in " & c1.Address
Exit Sub ' To step out after first error
End If
Next
End Sub
选项显式 私有子FindErrors() 调光范围 对于应用程序中的每个c。相交(_ ActiveSheet.UsedRange.SpecialCells(xlCellTypeVisible)_ ActiveSheet.UsedRange.SpecialCells(xlCellTypeBlanks)) 如果c.Interior.ColorIndex=16,则 c、 激活 MsgBox“地址中有错误”&c.地址 出口接头 如果结束 下一个c 端接头
试试这个:
如果c1.Interior.ColorIndex=16和c1.Value2=vbNullString,那么

顺便说一句,您的代码中有一个输入错误-在这一行中,您有
cl
而不是
c1
。是的,这是有效的,虽然我有一个不可预见的问题,因为条件格式似乎改变了单元格的颜色,但保留了原始的颜色索引。。也就是说,一些单元格不应该再被我们的代码检查,但仍然被列为代码24!!!有没有办法改变这一点? Option Explicit Private Sub FindErrors() Dim c As Range For Each c In Application.Intersect( _ ActiveSheet.UsedRange.SpecialCells(xlCellTypeVisible), _ ActiveSheet.UsedRange.SpecialCells(xlCellTypeBlanks)) If c.Interior.ColorIndex = 16 Then c.Activate MsgBox "Error in " & c.Address Exit Sub End If Next c End Sub