1

此宏旨在识别任何单元格中的字符串“%”,如果存在,则通过将其着色为黄色来识别它。

有趣的是,它确实有效,但我不断收到类型不匹配错误的后记,特别是在该行:

If InStr(rngCell.Value, "%") > 0 Then

这是我下面的完整代码:

Public Sub Markerrorvalues()

Dim iWarnColor As Integer
Dim rng As Range
Dim rngCell As Variant
Dim LR As Long
Dim vVal
Dim tRow

LR = Cells(Rows.Count, "B").End(xlUp).Row

Set rng = Range("C1:C" & LR)
iWarnColor = xlThemeColorAccent2

For Each rngCell In rng.Cells
    tRow = rngCell.Row
    If InStr(rngCell.Value, "%") > 0 Then
        rngCell.Interior.ColorIndex = iWarnColor
    Else
        rngCell.Interior.Pattern = xlNone
    End If
Next

End Sub

任何帮助,将不胜感激!

4

1 回答 1

1

可能您有一些带有错误值的单元格(例如#REF!#DIV/0!等)

要过滤掉这些,请将麻烦的代码包装在Not IsError条件中:

If Not IsError(rngCell.Value) Then 
    If InStr(rngCell.Value, "%") > 0 Then
        rngCell.Interior.ColorIndex = iWarnColor
    Else
        rngCell.Interior.Pattern = xlNone
    End If
EndIf
于 2013-05-13T09:09:49.910 回答