PDA

View Full Version : Solved: VBA Character colour change



tvanwyk
11-02-2007, 04:42 AM
Hi Guys,

I am trying to have the VBA Code run through the text in a range, one charatcer at a time.

The idea is that the code will verfiy if a character is a specific colour, and based on that change the change the individual character's colour accordingly.

Here is the code I am currently using::banghead:

Range("A3:A4").Select
For Each Character In Selection
If Character.Font.ColorIndex = xlAutomatic Then
Character.Font.ColorIndex = 2
Else
End If

If Character.Font.ColorIndex = 1 Then
Character.Font.ColorIndex = 2
Else
End If

If Character.Font.ColorIndex = 13 Then
Character.Font.ColorIndex = 13
Else
End If

If Character.Font.ColorIndex = 5 Then
Character.Font.ColorIndex = 5
Else
End If

Next Character

Please send me your comments and suggestions.

Thanks,

Theuns van Wyk

unmarkedhelicopter
11-02-2007, 04:46 AM
Pick a cell, get length of text, process text

Bob Phillips
11-02-2007, 05:30 AM
For Each cell In Range("A3:A4")
For i = 1 To Len(cell.Value)
If cell.Characters(i, 1).Font.ColorIndex = xlAutomatic Then
cell.Characters(i, 1).Font.ColorIndex = 3
ElseIf cell.Characters(i, 1).Font.ColorIndex = 1 Then
cell.Characters(i, 1).Font.ColorIndex = 2
ElseIf cell.Characters(i, 1).Font.ColorIndex = 13 Then
cell.Characters(i, 1).Font.ColorIndex = 13
ElseIf cell.Characters(i, 1).Font.ColorIndex = 5 Then
cell.Characters(i, 1).Font.ColorIndex = 5
End If
Next i
Next cell

tvanwyk
11-02-2007, 05:57 AM
Sweet. Thanks guys!!!