我正在寻找在特定列中搜索特定关键字并将其突出显示为黄色的Excel代码;并且能够为多个列做到这一点,每个列都有自己独特的关键字。用于突出显示Excel中特定列中特定单词的代码
示例:关键字 “河” 关键字 “海洋”
- 搜索列A每次,唯一关键字仅在特定列中突出显示,即使它也可能出现在其他列中。
该代码将包含100列,从“列A”到“列CV”,并允许为每列插入唯一关键字。
这可能吗?
通过论坛搜索,我找到了突出显示excel中特定单词的代码,但没有将搜索范围缩小到列并从其他列中排除关键字。
此代码,找到一个词,它颜色的红色,也有类似的核心思想是:
Sub colorText() Dim cl As Range Dim startPos As Integer Dim totalLen As Integer Dim searchText As String Dim endPos As Integer Dim testPos As Integer ' specify text to search. searchText = "river" ' loop trough all cells in selection/range For Each cl In Selection totalLen = Len(searchText) startPos = InStr(cl, searchText) testPos = 0 Do While startPos > testPos With cl.Characters(startPos, totalLen).Font .FontStyle = "Bold" .ColorIndex = 3 End With endPos = startPos + totalLen testPos = testPos + endPos startPos = InStr(testPos, cl, searchText, vbTextCompare) Loop Next cl End Sub
只有我需要一个黄色的亮点,而不是红色。我需要它为Excel 2016,并且这个代码是为excel 2010.
谢谢。
使用宏录制生成的代码,你可以为你的需要进行修改。可以使用VBA颜色常量,例如:'ActiveCell.Interior.Color = vbYellow' – June7