Originally Posted by
p45cal
Note: made some corrections after initially posting.
[vba]Sub HighlightWords2()
For Each cll In Range("A1:A72")
'create an array of the words in cll:
'clean punctuation fist:
cllStr = UCase(cll.Value)
cllStr = Replace(cllStr, "'", " ")
cllStr = Replace(cllStr, ",", " ")
cllStr = Replace(cllStr, "'", " ")
cllList = Split(Application.Trim(cllStr), " ")
For Each cll2 In Range("A76:A642").Cells
cll2List = Split(Application.Trim(UCase(cll2.Value)), " ") 'assumes lower section has no puntuation.
'if all words in cll2List are in cllList then highlight those words in cll.
AllWordsFound = True ' (will set this to FALSE if any word not found)
For Each word2 In cll2List
WordFound = False '(will set this to TRUE if the word is found)
For Each word In cllList
If word = word2 Then
WordFound = True
Exit For 'no need to keep on looking so abort inner loop
End If
Next word
If Not WordFound Then
AllWordsFound = False
Exit For 'no need to keep on looking so abort outer loop
End If
Next word2
If AllWordsFound Then 'do the highlighting:
For Each word2 In cll2List
cll.Characters(Start:=InStr(1, cll.Value, word2, vbTextCompare), Length:=Len(word2)).Font.ColorIndex = 3
Next word2
End If
Next cll2
Next cll
End Sub
[/vba]