View Single Post
 
Old 09-02-2021, 05:39 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

I'm going to assume that you have a regular table (no merged cells) and at least 2 columns and the code should be comparing the words in the first cell with all other cells on that row (like the original email). If these assumptions are correct then this modification to Paul's very elegant code should work.
Code:
Sub Demo()
  Application.ScreenUpdating = False
  Dim Tbl As Table, Rng As Range, strTxt As String, i As Long, j As Long
  Options.DefaultHighlightColorIndex = wdYellow
  For Each Tbl In ActiveDocument.Tables
    With Tbl
      For i = 1 To .Rows.Count
        Set Rng = .Rows(i).Range
        Rng.Start = .Cell(i, 2).Range.Start
        With .Cell(i, 1).Range
          For j = 1 To .Words.Count
            strTxt = Trim(.Words(j))
            With Rng.Find
              .ClearFormatting
              .Text = strTxt
              With .Replacement
                .ClearFormatting
                .Highlight = True
                .Text = "^&"
              End With
              .Format = True
              .Forward = True
              .MatchCase = False
              .MatchWholeWord = True
              .MatchWildcards = False
              .Wrap = wdFindStop
              .Execute Replace:=wdReplaceAll
            End With
          Next
        End With
      Next
    End With
  Next
  Application.ScreenUpdating = True
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote