我正在处理一个Excel文件,我有一个我需要搜索的单词列表,如果我找到它,我必须突出显示它的列。
我想使用CTRL + F,但我当时只能复制并粘贴一个单词,所以如果有办法通过使用VBA或条件格式自动执行此任务,我就会徘徊。
我在网上看过,但解决方案并没有很好地解决我的问题。
我在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