如何根据在两列中查找的字符串更改单元格填充颜色?

How do I change the cell fill color based on strings sought over two columns?

我有两列 (B 和 C) 包含名称,但我希望通过更改单元格填充颜色来确保标记某些词以供审阅。

看来我对 VBA 不太熟悉了,但我不得不涉猎一些以获得一个非常需要的宏来工作。就像我上面说的,我有两列(B 和 C)包含名称,但我希望通过更改单元格填充颜色来确保标记某些单词以供审阅。我要查找的词是 "hope" 和 "trust",它们可能是某些值的一部分。

Sub FindTrustHope()

Dim B As Long, C As Long, i As Long
Dim findTrust As String
Dim findHope As String
B = Cells(Rows.Count, "B").End(xlUp).Row
C = Cells(Rows.Count, "C").End(xlUp).Row
findTrust = "trust"
findHope = "hope"
    For i = B To 1 Step -1
    If Cells(i, "B") = findTrust Or Cells(i, "B") = findHope Then
        Cells(i, "B").Interior.Color = vbRed
    End If
    If Cells(i, "C") = findTrust Or Cells(i, "C") = findHope Then
        Cells(i, "C").Interior.Color = vbRed
    End If

Next i
End Sub

下面的代码应该可以帮到您。

Sub FindTrustHope()

Dim B As Long, C As Long, i As Long
Dim findTrust As String
Dim findHope As String
B = Cells(Rows.Count, "B").End(xlUp).Row
C = Cells(Rows.Count, "C").End(xlUp).Row
findTrust = "trust"
findHope = "hope"
    For i = B To 1 Step -1
    If InStr(Cells(i, "B"), findTrust) > 0 Or InStr(Cells(i, "B"), findHope) > 0 Then
        Cells(i, "B").Interior.Color = vbRed
    End If
    If InStr(Cells(i, "C"), findTrust) > 0 Or InStr(Cells(i, "C"), findHope) > 0 Then
        Cells(i, "C").Interior.Color = vbRed
    End If

Next i
End Sub