-1
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

我有这个代码可以在我的工作表中搜索颜色索引为 16 的非隐藏单元格。

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

这样消息仅在满足 3 个条件时出现。

感谢您的想法,

谢谢

4

2 回答 2

1

试试这个:If c1.Interior.ColorIndex = 16 And c1.Value2 = vbNullString Then

于 2013-02-06T17:46:30.797 回答
0

首先,使用Option Explicit!这样您就可以防止混淆clc1就像您在代码中所做的那样!此外,使用缩进使您的代码更易于阅读的最佳实践。

您可以通过以下方式实现您的愿望Application.Intersect

选项显式

私有子 FindErrors()
    调暗 c 作为范围
    对于 Application.Intersect( _
        ActiveSheet.UsedRange.SpecialCells(xlCellTypeVisible), _
        ActiveSheet.UsedRange.SpecialCells(xlCellTypeBlanks))

        如果 c.Interior.ColorIndex = 16 那么
            c.激活
            MsgBox "Error in " & c.Address
            退出子
        万一
    下一个 c
结束子
于 2013-02-06T17:46:20.133 回答