Custom Format font for "xx" to yellow

  • Thread starter Thread starter Guest
  • Start date Start date
You could use a macro.

Sub Color_String()
Dim Rng As Range
Dim cell As Range
Dim start_str As Integer
Set Rng = Selection
For Each cell In Rng
start_str = InStr(cell.Value, "xx")
If start_str Then
cell.Characters(start_str, 2).Font.ColorIndex = 6
End If
Next
End Sub

Or make it a worksheet event. Paste into the sheet module.

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "A1:A10"
On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
Dim Rng As Range
Dim cell As Range
Dim start_str As Integer
For Each cell In Target
start_str = InStr(cell.Value, "xx")
If start_str Then
cell.Characters(start_str, 2).Font.ColorIndex = 6
End If
Next
End If
ws_exit:
Application.EnableEvents = True
End Sub


Gord Dibben MS Excel MVP
 
Back
Top