M
Mike Magill
Hi,
I am trying to conditionally format the colour of the text in a cell
but I have too many conditions to be able to use the Conditional
Formatting function.
I have written the following code. It works perfectly on cells with
actual text in but doesn't change the font colour where the cell
contains a formula that produces a text result.
The result will always be a two character string and I want to colour
the first character one colour and the second character another
colour.
Any help would be greatly appreciated.
Thanks
Private Sub Worksheet_Change(ByVal Target As Range)
For Each C In Range("G12:BX64")
If (C.Value <> "") Then
On Error Resume Next
Select Case Left(C, 1)
Case "R"
With C.Characters(Start:=1, Length:=1).Font
.ColorIndex = 3
End With
With C.Characters(Start:=2, Length:=1).Font
.ColorIndex = 1
End With
With C
.Interior.ColorIndex = 3
End With
Case "A"
With C.Characters(Start:=1, Length:=1).Font
.ColorIndex = 45
End With
With C.Characters(Start:=2, Length:=1).Font
.ColorIndex = 1
End With
With C
.Interior.ColorIndex = 45
End With
Case "G"
With C.Characters(Start:=1, Length:=1).Font
.ColorIndex = 4
End With
With C.Characters(Start:=2, Length:=1).Font
.ColorIndex = 1
End With
With C
.Interior.ColorIndex = 4
End With
Case Else
With C.Characters(Start:=1, Length:=1).Font
.ColorIndex = 1
End With
With C
.Interior.ColorIndex = 0
End With
End Select
Select Case C
Case "RR"
With C.Characters(Start:=2, Length:=1).Font
.ColorIndex = 3
End With
Case "AA"
With C.Characters(Start:=2, Length:=1).Font
.ColorIndex = 45
End With
Case "GG"
With C.Characters(Start:=2, Length:=1).Font
.ColorIndex = 4
End With
End Select
End If
Next C
End Sub
I am trying to conditionally format the colour of the text in a cell
but I have too many conditions to be able to use the Conditional
Formatting function.
I have written the following code. It works perfectly on cells with
actual text in but doesn't change the font colour where the cell
contains a formula that produces a text result.
The result will always be a two character string and I want to colour
the first character one colour and the second character another
colour.
Any help would be greatly appreciated.
Thanks
Private Sub Worksheet_Change(ByVal Target As Range)
For Each C In Range("G12:BX64")
If (C.Value <> "") Then
On Error Resume Next
Select Case Left(C, 1)
Case "R"
With C.Characters(Start:=1, Length:=1).Font
.ColorIndex = 3
End With
With C.Characters(Start:=2, Length:=1).Font
.ColorIndex = 1
End With
With C
.Interior.ColorIndex = 3
End With
Case "A"
With C.Characters(Start:=1, Length:=1).Font
.ColorIndex = 45
End With
With C.Characters(Start:=2, Length:=1).Font
.ColorIndex = 1
End With
With C
.Interior.ColorIndex = 45
End With
Case "G"
With C.Characters(Start:=1, Length:=1).Font
.ColorIndex = 4
End With
With C.Characters(Start:=2, Length:=1).Font
.ColorIndex = 1
End With
With C
.Interior.ColorIndex = 4
End With
Case Else
With C.Characters(Start:=1, Length:=1).Font
.ColorIndex = 1
End With
With C
.Interior.ColorIndex = 0
End With
End Select
Select Case C
Case "RR"
With C.Characters(Start:=2, Length:=1).Font
.ColorIndex = 3
End With
Case "AA"
With C.Characters(Start:=2, Length:=1).Font
.ColorIndex = 45
End With
Case "GG"
With C.Characters(Start:=2, Length:=1).Font
.ColorIndex = 4
End With
End Select
End If
Next C
End Sub