I'm trying to conditionally format cells in a range using VBA. My goal is that every time a cell is selected, every cell which holds the same text will be formatted.
My code:
Private Sub Worksheet_SelectionChange(ByVal t As Range)
Cells.FormatConditions.Delete
Range("B2:K29").Select
Selection.FormatConditions.Add Type:=xlTextString, String:=t.Value, _
TextOperator:=xlContains
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.TintAndShade = 0
End With
End Sub
The problem is that every time I select a cell, all the cells in the range are formatted (and not just the ones which have the same text as in the selected cell).