【发布时间】:2014-03-05 09:21:33
【问题描述】:
我想为当前工作表中具有“#N/A”值的单元格着色。为此,我使用以下宏:
Sub ColorCells()
Dim Data As Range
Dim cell As Range
Set currentsheet = ActiveWorkbook.Sheets("Comparison")
Set Data = currentsheet.Range("A2:AW1048576")
For Each cell In Data
If cell.Value = "#N/A" Then
cell.Interior.ColorIndex = 3
End If
Next
End Sub
但是If cell.Value = "#N/A" Then 行给出了一个错误:类型不匹配。也许有人可以帮助了解错误在哪里?谢谢
【问题讨论】:
-
为什么不直接使用条件格式来突出显示有错误的单元格?)如果您不喜欢它,请使用
If cell.Text = "#N/A" Then。还有一个提示,尝试使用Set Data = Intersect(currentsheet.UsedRange,currentsheet.Range("A2:AW1048576"))来最小化循环中的单元格数。现在你循环遍历 5000 万 个细胞:) -
你也可以使用
IsError(Cell.Value) -
而不是 .value 使用 .text