Select a range of cells, then use the following code to highlight cells that contain a specified string

PHOTO EMBED

Wed Sep 08 2021 06:06:48 GMT+0000 (Coordinated Universal Time)

Saved by @cnewnham #vba

Sub ConditionalHighlightCells()

'Select a range of cells, then use the following code to highlight cells that contain a specified string

 

Set rngMine = Selection

For Each c In rngMine

     'highlight the cell containing "error"
    If InStr(1, c.Value, "error", vbTextCompare) Then 'I use InStr here (contains), but you can use c.value="error" for an exact match
        With c.Interior
            .Color = 65535 'yellow
            'Another format that can be used
            '.Color = RGB(200, 200, 255) ' RGB is Red, Green, Blue
            .Pattern = xlSolid
        End With
    End If
Next c

 

 End Sub
content_copyCOPY