在Excel中同时搜索(Ctrl + F)多个单词

时间:2019-03-07 23:31:47

标签: excel vba conditional-formatting

我正在处理一个Excel文件,并且有一个需要搜索的单词列表,如果找到它,则必须突出显示其列。

我想使用CTRL + F,但是一次只能复制和粘贴一个单词,所以我在徘徊,是否有办法使用VBA或条件格式来自动执行此任务。

我看了网上,但是解决方案对我的问题并不满意。

1 个答案:

答案 0 :(得分:1)

我在mrexcel.com(Find records and put into a summary sheet)上找到了此文件,并迅速对其进行了修改(感谢BrianB)。

请注意,您的标签页的命名方式与代码中的命名方式相同。这只是为了快速帮助您,并向您展示一种方式,我对其进行的编辑或评论还不是很好。

Sub FindRecords()
    Dim FromSheet As Worksheet
    Dim FromRow As Long
    Dim ToSheet As Worksheet
    Dim ToRow As Long
    Dim FindThis As Variant
    Dim FoundCell As Object
    '---------------------------------------------------
    Application.Calculation = xlCalculationManual
    Set FromSheet = ThisWorkbook.Worksheets("DataSheet")
    Set ToSheet = ThisWorkbook.Worksheets("Summary")
    ToRow = ThisWorkbook.Worksheets("Summary").UsedRange.SpecialCells(xlCellTypeLastCell).Row + 1
    '---------------------------------------------------
    '- get user input
    FindThis = InputBox("Please enter data to find : ")
    If FindThis = "" Then End ' trap Cancel
    '---------------------------------------------------
    '- clear summary for new data
    'ToSheet.Cells.ClearContents
    '---------------------------------------------------
    ' FIND DATA
    '-
    With FromSheet.Cells
        Set FoundCell = .Find(FindThis, LookIn:=xlValues)
        If Not FoundCell Is Nothing Then
            FirstAddress = FoundCell.Address
            '------------------------------------------
            '- copy data to summary
            'Do
                FromRow = FoundCell.Row
                ToSheet.Cells(ToRow, 1).Value = _
                        FromSheet.Cells(FromRow, 1).Value
                ToSheet.Cells(ToRow, 2).Value = _
                        FromSheet.Cells(FromRow, 2).Value
                ToSheet.Cells(ToRow, 3).Value = _
                        FromSheet.Cells(FromRow, 3).Value
                ToRow = ToRow + 1
                'Set FoundCell = .FindNext(FoundCell)
            'Loop While Not FoundCell Is Nothing And _
             '   FoundCell.Address <> FirstAddress
            '------------------------------------------
        End If
    End With
    MsgBox ("Done.")
    Application.Calculation = xlCalculationAutomatic
    FindRecords
End Sub