excellent find, stanleydgromjr!
i decided to use this code:
Sub ColorCertainWords()
Dim X As Long, Position As Long, Cell As Range, Words As Variant, Parts() As String
Words = Array("gross proceeds//red//3", _
"market value//red//3", _
"enhancing the value//red//3", _
"used off//red//3") '<-- add more if needed
For Each Cell In Range("B1", Cells(Rows.Count, "B").End(xlUp))
If Len(Cell.Value) Then
For X = LBound(Words) To UBound(Words)
Parts = Split(Words(X), "//")
If UBound(Parts) >= 0 Then
Position = InStr(1, Cell.Value, Parts(0), vbTextCompare)
Do While Position
With Cell.Characters(Position, Len(Parts(0))).Font
.ColorIndex = Parts(2)
.Bold = True
End With
Position = InStr(Position + 1, Cell.Value, Parts(0), vbTextCompare)
Loop
End If
Next
End If
Next
End Sub
my question is how do i edit this code to work not only in column B but also column H (ie, look for all keywords in columns B and H)
would be really nice if i could figure out a way to modify this code to fit my needs. this code should alow me to paste my keywords in a separate sheet
Sub ColorCertainWords()
Dim X As Long, Z As Long, LastRow As Long, Position As Long, Colors(1 To 3) As Long
Dim Temp As String, Words As Variant, Cell As Range
Const Red As Long = 3
Const Green As Long = 4
Const Blue As Long = 5
Colors(1) = Red
Colors(2) = Green
Colors(3) = Blue
For Each Cell In Sheets("Clauses").Range("B1", Sheets("Clauses").Cells(Rows.Count, "B").End(xlUp))
If Len(Cell.Value) Then
For X = 1 To 3
LastRow = Sheets("Lists").Cells(Rows.Count, X).End(xlUp).Row
Words = Range(Sheets("Lists").Cells(3, X), Sheets("Lists").Cells(LastRow, 3))
If Not IsArray(Words) Then
Temp = Words
ReDim Words(1 To 1, 1 To 1)
Words(1, 1) = Temp
End If
For Z = 1 To UBound(Words)
Position = InStr(1, Cell.Value, Words(Z, 1), vbTextCompare)
Do While Position
With Cell.Characters(Position, Len(Words(Z, 1))).Font
.ColorIndex = Colors(X)
.Bold = True
End With
Position = InStr(Position + 1, Cell.Value, Words(Z, 1), vbTextCompare)
Loop
Next
Next
End If
Next
End Sub
Bookmarks