简体   繁体   English

如何使用宏在excel中搜索并突出显示单元格内的多个单词?

[英]How to search and highlight multiple words inside cells in excel using macros?

I have paragraphs in each cell that I want to parse through to find specific words and then highlight them (not just the cell). 我想解析每个单元格中的段落以找到特定的单词,然后突出显示它们(而不仅仅是单元格)。 It can be hard coded. 它可以被硬编码。 I searched online and did not find anything that fixed the problem I am facing. 我在网上搜索,但找不到能解决我所面临问题的任何东西。 Thank you so much. 非常感谢。

You cannot highlight individual words even manually. 您甚至不能手动突出显示单个单词。 You could, however, change an individual word's font color. 但是,您可以更改单个单词的字体颜色。

According to this link , you can try this: 根据此链接 ,您可以尝试以下操作:

Option Explicit

Sub Highlight()

    Dim rCell    As Range
    Dim zFind    As String
    Dim lFindLen As Long

    zFind = "test"
    lFindLen = Len(zFind)

    For Each rCell In Selection

       With rCell
          .Characters(Start:=InStr(.Value, zFind), Length:=lFindLen) _
          .Font.ColorIndex = 3  'Red -- Yellow too hard to read!
       End With

    Next rCell

End Sub 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM