Excel VBA突出显示搜索

时间:2016-04-12 04:36:11

标签: excel vba excel-vba

我正在尝试在一个单元格中使用单词,然后转到另一个单词并在另一个单元格中找到该单词。棘手的部分是第二张纸在很多地方都有这个词,我只希望那个单词突出显示为蓝色。

我尝试了以下内容,但循环继续通过蓝色突出显示的单词并继续。我做错了什么?

Sub TryingIt()

Dim r As Excel.Range
Dim strName As String
Dim strFirstFound As String

strName = ActiveCell.Text

Sheets("Waiting For").Select

Range("A1").Select

Cells.Find(What:=strName, After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Activate

Set r = ActiveCell

If r.Interior.color = vbBlue Then
r.Offset(1, 0).Select
Else:
    Do
    Cells.Find(What:=strName, After:=ActiveCell, LookIn:=xlFormulas, _
    LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Activate

    Set r = ActiveCell

    Loop While r.Interior.color <> vbBlue

r.Offset(1, 0).Select

End If

End Sub

1 个答案:

答案 0 :(得分:1)

以下是答案:

你必须小心对颜色有更具体的了解。就我而言,它是RGB(0,176,240),而不仅仅是vbBlue