跳到主要内容

在Excel中搜索并突出显示搜索结果

在Excel中,可以使用“查找和替换”功能来查找特定值,但是您知道如何在搜索后突出显示搜索结果吗? 在本文中,我介绍了两种不同的方法来帮助您在Excel中同时搜索和突出显示搜索结果。

通过VBA代码搜索并突出显示搜索结果

通过条件格式搜索并突出显示搜索结果

通过方便的工具搜索和突出显示搜索结果


通过VBA代码搜索并突出显示搜索结果

在Excel中,有一个VBA代码可以帮助您搜索值,然后突出显示搜索结果。

1.启用要搜索的工作表并突出显示结果,然后按 Alt + F11键 打开钥匙 Microsoft Visual Basic应用程序 窗口。

2。 点击 插页 > 模块,然后将以下代码粘贴到新模块中。

VBA:突出显示搜索结果

Sub FindRange()
'UpdatebyExtendoffice20190813
Dim xRg As Range
Dim xFRg As Range
Dim xStrAddress As String
Dim xVrt As Variant
xVrt = Application.InputBox(prompt:="Search:", Title:="www.extendoffice.com")
If xVrt <> "" Then
Set xFRg = ActiveSheet.Cells.Find(what:=xVrt)
If xFRg Is Nothing Then
MsgBox prompt:="Cannot find this value", Title:="www.extendoffice.com"
Exit Sub
End If
xStrAddress = xFRg.Address
Set xRg = xFRg
Do
Set xFRg = ActiveSheet.Cells.FindNext(After:=xFRg)
Set xRg = Application.Union(xRg, xFRg)
Loop Until xFRg.Address = xStrAddress
If xRg.Count > 0 Then
xRg.Interior.ColorIndex = 8
xRsp = MsgBox(prompt:="Do you want to cancel highlighting?", Title:="www.extendoffice.com", Buttons:=vbQuestion + vbOKCancel)

If xRsp = vbOK Then xRg.Interior.ColorIndex = xlNone
End If
End If
End Sub

doc搜索突出显示搜索结果1

3。 按 F5 键,然后会弹出一个搜索框供您键入要搜索的指定值。
doc搜索突出显示搜索结果2

4。 点击 OK,匹配的结果以背景色突出显示。 此外,还会弹出一个对话框,询问您是否取消突出显示。 请点击 OK 要取消突出显示并关闭对话框,请单击 取消 保持突出显示并关闭对话框。
doc搜索突出显示搜索结果3

备注:

1.如果找不到匹配的值,则会弹出一个对话框提醒您。
doc搜索突出显示搜索结果4

2.此VBA适用于整个活动工作表且不区分大小写。

其他

您想加薪并有很多时间陪伴家人吗?

Office 选项卡可立即将 Microsoft Office 工作效率提高 50%

令人难以置信的是,处理两个或多个文档比处理一个或多个文档更容易,更快捷。

与知名浏览器相比,Office Tab中的选项卡式工具更强大、更高效。

每天为您减少数百次鼠标单击和键盘输入,现在告别鼠标手。

如果您经常处理多个文档,Office Tab 将非常适合您节省时间。

30-天免费试用,无需信用卡。

了解更多现在免费下载


通过条件格式搜索并突出显示搜索结果

在Excel中,条件格式设置功能还可以自动突出显示搜索结果。

假设数据和搜索框显示如下屏幕截图,请按照以下步骤操作:
doc搜索突出显示搜索结果5

1.选择要搜索的范围,然后单击 主页 > 条件格式 > 新规则.
doc搜索突出显示搜索结果6

2.在 新格式规则 对话框中选择 使用公式来确定要格式化的单元格 ,在 选择规则类型 部分,然后转到下面的文本框 格式化此公式为真的值,类型 = AND($ E $ 2 <>“”,$ E $ 2 = A4).

E2是您将放置搜索值的单元格,而A4是您要搜索的范围内的第一个单元格。
doc搜索突出显示搜索结果7

3。 点击 格式 按钮,转到 单元格格式 对话框下 标签,根据需要选择一种颜色。 请点击 OK > OK 关闭对话框。
doc搜索突出显示搜索结果8

从现在开始,当您在单元格E2中输入关键字时,搜索结果将在指定范围内自动突出显示。


通过方便的工具搜索和突出显示搜索结果

如果要搜索两个或多个值并一次突出显示搜索结果,则 标记关键字 的特点 Kutools for Excel 可以给你一个忙。

Kutools for Excel 是一个功能强大的插件,收集了 300 多个方便的工具,可提高您在 Excel 工作中的效率,点击立即获得 30 天免费试用。

1. 选择要搜索的数据范围,点击 库工具 > 文本 > 标记关键字.
doc搜索突出显示搜索结果8

2. 在弹出的对话框中,键入要搜索的值并用逗号分隔 关键字 文本框。 然后选择 标记选项 以及您需要的字体颜色。 点击 Ok.

如果要搜索区分大小写的值,请勾选 区分大小写 复选框。
doc搜索突出显示搜索结果8

然后匹配的结果将以不同的字体颜色突出显示。
doc搜索突出显示搜索结果8

随着 标记关键字 功能,您还可以在范围内找到部分字符串。 假设搜索单元格包含球或跳跃,输入球,跳入 关键字 文本框,然后指定设置并单击 Ok.
doc搜索突出显示搜索结果8doc搜索突出显示搜索结果8


示例文件

点击下载示例文件


与条件格式化有关的其他操作(文章)

在Excel中使用条件格式按颜色计算/求和单元格
现在,本教程将告诉您一些便捷的方法,以Excel中的条件格式通过颜色快速计数或求和单元格。

在Excel中使用条件格式创建图表
例如,您有一个班级的成绩表,并且想要创建一个图表以对不同范围内的成绩进行着色,此处本教程将介绍解决此工作的方法。

Excel中的条件格式堆积条形图
本教程介绍了如何创建条件格式的堆积条形图,如下图在Excel中逐步显示的屏幕截图。

如果Excel中两列相等,则条件格式化行或单元格的格式
在本文中,我将介绍在Excel中两列相等的情况下对行或单元格进行格式设置的方法。

对Excel中的每一行应用条件格式
有时,您可能需要为每行应用条件格式。 除了为每行重复设置相同的规则外,解决此工作还有一些技巧。


  • 超级公式栏 (轻松编辑多行文本和公式); 阅读视图 (轻松读取和编辑大量单元格); 粘贴到过滤范围...
  • 合并单元格/行/列 和保存数据; 拆分单元格内容; 合并重复的行和总和/平均值...防止细胞重复; 比较范围...
  • 选择重复或唯一 行; 选择空白行 (所有单元格都是空的); 超级查找和模糊查找 在许多工作簿中; 随机选择...
  • 确切的副本 多个单元格,无需更改公式参考; 自动创建参考 到多张纸; 插入项目符号,复选框等...
  • 收藏并快速插入公式,范围,图表和图片; 加密单元 带密码 创建邮件列表 并发送电子邮件...
  • 提取文字,添加文本,按位置删除, 删除空间; 创建和打印分页小计; 在单元格内容和注释之间转换...
  • 超级筛选 (将过滤方案保存并应用于其他工作表); 高级排序 按月/周/日,频率及更多; 特殊过滤器 用粗体,斜体...
  • 结合工作簿和工作表; 根据关键列合并表; 将数据分割成多个工作表; 批量转换xls,xlsx和PDF...
  • 数据透视表分组依据 周号,周几等 显示未锁定的单元格 用不同的颜色 突出显示具有公式/名称的单元格...
kte选项卡201905
  • 在Word,Excel,PowerPoint中启用选项卡式编辑和阅读,发布者,Access,Visio和Project。
  • 在同一窗口的新选项卡中而不是在新窗口中打开并创建多个文档。
  • 每天将您的工作效率提高50%,并减少数百次鼠标单击!
officetab底部
Comments (10)
Rated 4.5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
how do I make a VBA to search a few times with different highlight color?

and

then how do i make the highlight area, not only in the exact cell but also the cells next to it, or the whole row?

Please advice.

Thank you.
Rated 4.5 out of 5
This comment was minimized by the moderator on the site
how about highlight the keyword's row or column or the 3 cells next to the keyword?

and how do i search multiple times with different color of highlight?
This comment was minimized by the moderator on the site
How would I make the data entry box reopen after hitting ok? I use this macro with a barcode scanner and would like to be able to keep scanning without having to rerun macro each time. Example open macro scan it finds and highlights then reopens for next scan.
This comment was minimized by the moderator on the site
Hi, I have office 365 but when I went to Kutools > Text > I could not find Mark Keyword. Is there feature still there? Thanks
This comment was minimized by the moderator on the site
Hi, Kimber, what version of Kutools for Excel you use? Mark Keyword released after Kutools for Excel 24.0. If your version is lower than 24.0, please upgrade your version.
This comment was minimized by the moderator on the site
Does it work for Excel 2013 and what do I have to change in order to fit in with the 2003 version? I’ve tried your code but there is no button to save the module
This comment was minimized by the moderator on the site
Sorry, it’s Excel 2003
This comment was minimized by the moderator on the site
How can you modify this to also jump to the cell that is being highlighted.
This comment was minimized by the moderator on the site
Hi, Jeff, if you want to select all highlighted cells, just add
xRg.Select
at the end of the above code, see screenshot:
https://www.extendoffice.com/images/stories/comments/sun-comment/doc-jump-to-highlighted-cell-1.png
If you want to jump to the first highlighted cell, add
xRg.Areas(xRg.Areas.Count)(1).Select
at the end of the above code, see screenshot:
https://www.extendoffice.com/images/stories/comments/sun-comment/doc-jump-to-highlighted-cell-2.png
This comment was minimized by the moderator on the site
Hi thanks for your help but when we click ok for cancel highlighting. color of cell change. I want orignal color after cancel. What code i need to change in VBA.
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations