Try this macro (created by AI):
Code:
Sub ShadeCellsInTable()
Dim selectedRange As Range
Dim tbl As Table
Dim cell As Cell
Dim findText As String
Dim alertMessage As String
' Set the text you want to find
findText = "Name"
' Set the alert message
alertMessage = "Please select a table."
' Check if a range is selected
If Selection.Type <> wdSelectionIP Then
Set selectedRange = Selection.Range
' Check if the selection is a table
If selectedRange.Tables.Count > 0 Then
Set tbl = selectedRange.Tables(1)
' Loop through each cell in the table
For Each cell In tbl.Range.Cells
' Check if the cell contains the find text
If InStr(cell.Range.Text, findText) > 0 Then
' Shade the cell if it contains the find text
cell.Shading.BackgroundPatternColor = wdColorGray25
End If
Next cell
Else
' Show an alert if a table is not selected
MsgBox alertMessage, vbInformation, "Word Macro"
End If
Else
' Show an alert if a range is not selected
MsgBox alertMessage, vbInformation, "Word Macro"
End If
End Sub