Note: The other languages of the website are Google-translated. Back to English
Log in  \/ 
Register  \/ 


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 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()
Dim xRg As Range
Dim xFRg As Range
Dim xStrAddress As String
Dim xVrt As Variant
xVrt = Application.InputBox(prompt:="Search:", Title:="")
If xVrt <> "" Then
Set xFRg = ActiveSheet.Cells.Find(what:=xVrt)
If xFRg Is Nothing Then
MsgBox prompt:="Cannot find this value", Title:=""
Exit Sub
End If
xStrAddress = xFRg.Address
Set xRg = xFRg
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:="", 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


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.

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
Say something here...
symbols left.
You are guest
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Akash · 1 years ago
    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.