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
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
3. Press F5 key, then a searching box pops out for you to type the specified value you search.
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.
Note:
1. If there is no matched value found, a dialog pops out to remind you.
2. This VBA works for the whole active sheet and case insensitive.
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. |
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:
1. Select the range you want to search in, and click Home > Conditional Formatting > New Rule.
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.
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.
From now on, when you enter the keyword in Cell E2, the search results will be automatically highlighted in the specified range.
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.
1. Select the data range you want to search, click Kutools > Text > Mark Keyword.
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.
Then the matched results will highlight with a different font color.
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.
Sample File
Click to download the sample file
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.
The Best Office Productivity Tools
Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%
- 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...
- 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!