Excel 查找多个关键字并高亮显示该行
在表1中,我有多个行和列(比如A列到K列,至少有1000行)。在表2中,我列出了关键词(A列带有keyworks A1-A50) 我试图找到一个宏,该宏使用tab 2中的任何关键字搜索tab 1,并高亮显示tab 1中找到它的单元格Excel 查找多个关键字并高亮显示该行,excel,vba,Excel,Vba,在表1中,我有多个行和列(比如A列到K列,至少有1000行)。在表2中,我列出了关键词(A列带有keyworks A1-A50) 我试图找到一个宏,该宏使用tab 2中的任何关键字搜索tab 1,并高亮显示tab 1中找到它的单元格 如何为此编写宏?我不熟悉宏世界和excel。如果您不提供代码或屏幕截图,我将不胜感激。很难回答 Option Explicit Sub ColourMatchingCells() With Thism Tab2range as range 'Replace Sh
如何为此编写宏?我不熟悉宏世界和excel。如果您不提供代码或屏幕截图,我将不胜感激。很难回答
Option Explicit
Sub ColourMatchingCells()
With Thism Tab2range as range
'Replace Sheet2 below with whatever Tab 2 is named -- and A1:A50 with actual range address.'
Set Tab2range = .worksheets("Sheet2).range("A1:A50")
Dim cell as range
' Again, replace Sheet1 name and range address on next line with actual values'
With .worksheets("Sheet1").range("A1:K1000")
Dim AddressOfFirstMatch as string
Dim CellFound as range
Dim MatchAddress as string
For each cell in Tab2range
' Case insensitive search and which tries to find the whole value. You did not mention what type of data you're searching for e.g. strings, numbers, dates, etc. -- or what type of search you want. '
Set CellFound = .cells.find(what:=cell.value2,lookin:=xlvalues,lookat:=xlwhole,searchdirection:=xlnext,Matchcase:=False)
If not (CellFound is nothing) then
AddressOfFirstMatch = CellFound.address
CellFound.interior.color = vbblue 'just an example'
Do
Set CellFound = .findnext(CellFound)
CellFound.interior.color = vbblue
MatchAddress = CellFound.address
Doevents ' If you experience infinite loop or bad logic, spam/hold Escape or Break key on keyboard'
Loop until strcomp(AddressOfFirstMatch,MatchAddress, vbbinarycompare) = 0
End if
Next cell
End with
End with
End Sub
它有用吗?它能做你想做的吗?最好的开始是在手动执行宏的同时录制宏。然后它会为您编写代码。