Quote:
Originally Posted by Kater
Hello! I have documents that often contain tables where the first column says "NAME:" and then the corresponding row in the second column is where that person would enter their name.
I would like a macro that would highlight the column 2 text (the person's name) IF it does not begin with "AGENT." For example, column 1 says "NAME:", column 2 says "BOB JONES" but it should say "AGENT BOB JONES."
I would prefer the macro to highlight the text (any color is fine) rather than shade the cell.
Also, the macro would need to just end if there happen to not be any tables in said document.
Is that possible?
|
Code:
Sub HighlightNames()
Dim oTable As Table
Dim oRow As Row
Dim oRange As Range
If ActiveDocument.Tables.Count = 0 Then Exit Sub
For Each oTable In ActiveDocument.Tables
For Each oRow In oTable.Rows
Set oRange = oRow.Cells(2).Range
oRange.End = oRange.End - 1
If Not oRange.Text Like "AGENT*" Then
oRange.HighlightColorIndex = wdYellow
End If
Next oRow
Next oTable
End Sub