Skip to main content

Search and highlight search results in Excel

In Excel, you can use the Find and Replace function to find a specific value, but do you know how to highlight the search results after searching? In this article, I introduce two different ways to help you search and highlight search results at the meanwhile in Excel.

Search and highlight search results by the VBA code

Search and highlight search results by the Conditional Formatting

Search and highlight search results by a handy tool


Search and highlight search results by the VBA code

In Excel, there is a VBA code that can help you search a value and then highlight the search results.

1. Enable the sheet you want to search and highlight results, press Alt + F11 keys to open Microsoft Visual Basic for Applications window.

2. Click Insert > Module, and paste below code to the new module.

VBA: Highlight search results

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 search highlight search result 1

3. Press F5 key, then a searching box pops out for you to type the specified value you search.
doc search highlight search result 2

4. Click OK, the matched results have been highlighted with a background color. Also, a dialog pops out to ask you if cancel the highlighting. Click OK to cancel the highlighting and close the dialog, click Cancel to keep the highlighting and close the dialog.
doc search highlight search result 3

Note:

1. If there is no matched value found, a dialog pops out to remind you.
doc search highlight search result 4

2. This VBA works for the whole active sheet and case insensitive.

ot move

Do You Want To Have A Pay Raise and Much Time To Accompany With Family?

Office Tab Enhances Your Efficiency By 50% In Microsoft Office Working Right Now

Unbelievable, working at two or more documents is easier and faster than working at one.

Compareed with well-known browsers, the tabbed tool in Office Tab is more powerful and more efficient.

Reduce hundreds of mouse-clicks and keyboard typing every day for you, say goodbye to the mouse hand now.

If you usually work at multiple documents, Office Tab will be a great time-saver for you.

30-day free trial, no credit card required.

Read MoreFree Download Now


Search and highlight search results by the Conditional Formatting

In Excel, the Conditional Formatting function also can automatically highlight the search results.

Supposing the data and search box display as below screenshot, now please do as below steps:
doc search highlight search result 5

1. Select the range you want to search in, and click Home > Conditional Formatting > New Rule.
doc search highlight search result 6

2. In the New Formatting Rule dialog, select Use a formula to determine which cells to format in the Select a Rule Type section, then go to the text box under Format values where this formula is true, type =AND($E$2<>"",$E$2=A4).

E2 is the cell you will place the search value, and A4 is the first cell in the range where you search in.
doc search highlight search result 7

3. Click Format button, go to the Format Cells dialog, under Fill tab, choose one color as you need. Click OK > OK to close the dialogs.
doc search highlight search result 8

From now on, when you enter the keyword in Cell E2, the search results will be automatically highlighted in the specified range.


Search and highlight search results by a handy tool

If you want to search two or more values and highlight the search results once time, the Mark Keyword feature of Kutools for Excel could give you a favor.

Kutools for Excel is a powerful add-in that collects more than 300 handy tools for enhance your efficiency in Excel jobs,click to get 30-day free trial now.

1. Select the data range you want to search, click Kutools > Text > Mark Keyword.
doc search highlight search result 8

2. In the popping dialog, type the values that you want to search and separated by comma in Keyword textbox. Then choose the Mark Options and the font color as you need. Click Ok.

If you want to search value in case sensitive, tick Match Case checkbox.
doc search highlight search result 8

Then the matched results will highlight with a different font color.
doc search highlight search result 8

With the Mark Keyword feature, you also can find part of string in the range. Supposing search cells contains ball or jump, type ball, jump into the Keyword textbox, then specify the settings and click Ok.
doc search highlight search result 8doc search highlight search result 8


Sample File

Click to download the sample file


Other Operations (Articles) Related To Conditioanl Formatting

Count/sum cells by colors with conditional formatting in Excel
Now this tutorial will tell you some handy and easy methods to quickly count or sum the cells by color with conditional formatting in Excel.

Create a chart with conditional formatting in Excel
For example, you have a score table of a class, and you want to create a chart to color scores in different ranges, here this tutorial will introduce the method on solving this job.

Conditional formatting stacked bar chart in Excel
This tutorial, it introduces how to create conditional formatting stacked bar chart as below screenshot shown step by step in Excel.

Conditional formatting rows or cells if two columns equal in Excel
In this article, I introduce the method on conditional formatting rows or cells if two columns equal in Excel.

Apply conditional formatting for each row in Excel
Sometimes, you may want to apply the conditional formatting for per row. Except repeatedly setting the same rules for per row, there are some tricks on solving this job.


  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns and Keeping Data; Split Cells Content; Combine Duplicate Rows and Sum/Average... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Favorite and Quickly Insert Formulas, Ranges, Charts and Pictures; Encrypt Cells with password; Create Mailing List and send emails...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • Pivot Table Grouping by week number, day of week and more... Show Unlocked, Locked Cells by different colors; Highlight Cells That Have Formula/Name...
kte tab 201905
  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
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