搜索关键词列表

时间:2019-11-21 05:13:30

标签: excel vba

它需要在列中搜索关键字。

如果找到了相同的关键字,则需要更新“找到的行”的下一列

我正在尝试编写一个代码,以搜索excel工作表列“ B”中的关键字列表,然后如果找到了关键字,则将“所有找到的行”分组为更新的相同关键字“下一列”。

在工作表中经常出现该特定单词。我要做的就是搜索这些出现的内容,然后对包含这些单词的所有行进行分组。我的问题是我不确定要使用哪种循环结构。下面是我正在使用的代码。

Sub TestDeleteRows()
    Dim rFind As Range
    Dim rDelete As Range
    Dim strSearch As String
    Dim sFirstAddress As String
    'Dim SearchRange As Range

    'Set SearchRange = ThisWorkbook.Worksheets("KeyWords").Range("A1:A5")

    strSearch = "Password"
    Set rDelete = Nothing

    Application.ScreenUpdating = False

    With Sheets("Tags").Columns("B:B")
        Set rFind = .Find(strSearch, LookIn:=xlValues, _
        LookAt:=xlPart, SearchDirection:=xlNext, MatchCase:=False)
        If Not rFind Is Nothing Then
            sFirstAddress = rFind.Address
            Do
                If rDelete Is Nothing Then
                    Set rDelete = rFind
                Else
                    Set rDelete = Application.Union(rDelete, rFind)
                End If
                Set rFind = .FindNext(rFind)
            Loop While Not rFind Is Nothing And rFind.Address <> sFirstAddress

            rDelete.Offset(rDelete, 1).Value = strSearch 'I am not getting the output Hear
        End If
    End With
    Application.ScreenUpdating = True
End Sub

0 个答案:

没有答案