Written by Allen Wyatt (last updated June 2, 2022)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and 2021
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
Note:
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 2021. You can find a version of this tip for the older menu interface of Word here: Noting Table Rows Containing a Character.
Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!
When you print a table that includes borders, those borders should be crisp and clear on the printout. If you get some ...
Discover MoreWhen pasting a table into your document, you might discover that it extends beyond the right margin of your page. Here ...
Discover MoreWhen working with tables, a common editing task is to combine two tables into one. Sometimes, though, you may run into ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2018-05-06 23:51:39
Stella
Why do you define 'iCol' as 'Integer' and then not use 'iCol' anywhere in the macro?
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.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments