Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, and Word in Office 365. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Noting Table Rows Containing a Character.
by Allen Wyatt
(last updated April 28, 2018)
Sub HilightRows() Dim TargetText1 As String Dim TargetText As String Dim oRow As Row Dim iCol As Integer 'initialize the target characters to find TargetText = "(" TargetText1 = ")" 'Make sure we're in a table If Selection.Information(wdWithInTable) Then 'Clear all the old shading Selection.Tables(1).Shading.BackgroundPatternColor = wdColorWhite 'do all the rows For Each oRow In Selection.Tables(1).Rows If InStr(oRow.Range.Text, TargetText) > 0 Then _ oRow.Shading.BackgroundPatternColor = wdColorYellow If InStr(oRow.Range.Text, TargetText1) > 0 Then _ oRow.Shading.BackgroundPatternColor = wdColorYellow Next oRow End If End Sub
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (11435) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Office 365. You can find a version of this tip for the older menu interface of Word here: Noting Table Rows Containing a Character.
The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!
Need to make sure that all the cells of a table have something in them? It's easy to do with a handy little macro.Discover More
If you have a common table layout that you want to use again and again, you'd benefit by having an easy way to save that ...Discover More
Selecting rows and columns in tables is a common task. Because of this, Word provides a couple of ways you can accomplish ...Discover More
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.