跳到主要內容

在Excel中搜索並突出顯示搜索結果

在Excel中,可以使用“查找和替換”功能來查找特定值,但是您知道如何在搜索後突出顯示搜索結果嗎? 在本文中,我介紹了兩種不同的方法來幫助您在Excel中同時搜索和突出顯示搜索結果。

通過VBA代碼搜索並突出顯示搜索結果

通過條件格式搜索並突出顯示搜索結果

通過方便的工具搜索和突出顯示搜索結果


通過VBA代碼搜索並突出顯示搜索結果

在Excel中,有一個VBA代碼可以幫助您搜索值,然後突出顯示搜索結果。

1.啟用要搜索的工作表並突出顯示結果,然後按 Alt + F11鍵 打開鑰匙 Microsoft Visual Basic for Applications 窗口。

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中輸入關鍵字時,搜索結果將在指定範圍內自動突出顯示。


通過方便的工具搜索和突出顯示搜索結果

如果要搜索兩個或多個值並一次突出顯示搜索結果,則 標記關鍵字 的特點 Excel的Kutools 可以給你一個忙。

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