VBA code for find keyword in column E if found, change font color in matching B column cell


New Member
Hi newbie Excel macros and VBA user here...

I need either macro or VBA code to do the following:

find keyword (not case sensitive) in column E which contains various text notes.
if found, change font color in matching B column cell
Then repeat for all cells in column to final row.
Note I have 3 sections of rows in the spread that are separated by blank rows for subtotalling.

Note2: I actually have two keywords ("died" and "d/c") that I need to find then colorcode the B col cell font
different colors. Bold Blue for died. And bold green for d/c.

I think I should be able to do with a loop or If, Elseif type vba code...but can't figure how to write it.

Would so appreciate any help.



MrExcel MVP, Moderator
Hi & welcome to MrExcel.
How about
Sub tkbaty()
    With ActiveSheet
        .Range("A1:E1").AutoFilter 5, "*died*"
        With .AutoFilter.Range.Offset(1).Columns(2).Font
            .Bold = True
            .Color = vbBlue
        End With
        .Range("A1:E1").AutoFilter 5, "*d/c*"
        With .AutoFilter.Range.Offset(1).Columns(2).Font
            .Bold = True
            .Color = vbGreen
        End With
        .AutoFilterMode = False
    End With
End Sub


Well-known Member
Option Explicit
Option Compare Text

Sub tkbaty()
    Dim i As Long, lr As Long
    lr = Range("E" & Rows.Count).End(xlUp).Row
    Application.ScreenUpdating = False
    For i = 1 To lr
        If Range("E" & i) = "died" Then
            Range("B" & i).Font.Color = vbBlue
            Range("B" & i).Font.Bold
        ElseIf Range("E" & i) = "d/c" Then
            Range("B" & i).Font.Color = vbGreen
            Range("B" & i).Font.Bold
        End If
    Next i
    Application.ScreenUpdating = True
    MsgBox "complete"
End Sub

Some videos you may like

This Week's Hot Topics

  • Importing multiple excel files into one spreadsheet
    Hi, I'm trying to import multiple excel files (with the same format into a single spreadsheet) so that each day's file is listed underneath the...
  • find many based on a certain criteria
    good evening, I hope someone can help me? I have a workbook sheet 2 contains lots of data.... I would like to be able to find anything on sheet...
  • How to copy multiple rows using If
    Hi all, I'm very new to VBA and have written this simple code to copy certain cells if a certain cell within that row contains any data. I need...
  • VBA If statement
    Dear All, I have two dates, where I'd like a message box to pop, if the dates are between this criteria. [CODE] sDate1 = #10/1/2019#...
  • Text Format
    I have a sheet for user to keyin the data. The format of the data can be 451 / 1903, 0012 / 9908 or 00287 / 0099. The number after the "/" is...
  • Syntax errors
    Good Morning, Trying to compile a workbook, I keep getting a few errors. Here are the first two: [code=rich]Syntax Error: Function...