I have a macro that changes the background colour of a table in Word depending upon the text within the same cell - akin to Excel's conditional formatting rules.
However I want to restrict this to a specific column - column 2 in a table of many rows but two columns: column 1 being where the question is and column 2 is where the user inputs the answer from a dropdown list - and depending upon the answer the cell changes colour.
My code is below; but this is applying it to both columns.
Anyone know how to re-code so it only applies to table column 2. I am using MS Word 2016.
Thanks
Dim r As Range
Sub UBC ()
color "No", wdRed
color "Yes", wdGreen
color "Unknown", wdYellow
color "Not Applicable", wdGray50
End Sub
Function color(text As String, backgroundColor As WdColorIndex)
Set r = ActiveDocument.Range
With r.Find
Do While .Execute(FindText:=text, MatchWholeWord:=True, Forward:=True) = True
r.Cells(1).Shading.BackgroundPatternColorIndex = backgroundColor
Loop
End With
End Function