如何突出显示单元格中特定子字符串的所有发生?

时间:2015-09-04 17:33:56

标签: excel vba excel-vba

我一直在使用下面的内容,但发现它只突出显示/更改每个单元格的第一个子字符串的字体颜色。我如何确定它还突出了后续的?

Sub test4String2color()
    Dim strTest As String
    Dim strLen As Integer
    strTest = Range("F1")
    strLen = Len(strTest)
    For Each cell In Range("A1:D100")
      If InStr(cell, strTest) > 0 Then
       cell.Characters(InStr(cell, strTest), strLen).Font.Color = vbRed
     End If
    Next
End Sub

1 个答案:

答案 0 :(得分:0)

你只需循环遍历字符串,直到找不到 strTest 。使用上一个查找的位置开始连续搜索。

rgl