Forum Discussion
highlight / color change, a particular character in a cell of a worksheet
Thanks for the reply. I am not expert in macros or VB. one more doubt, instead of red , how can change the colour codes to green, blue, yellow. Thanks for your help
Unfortunately, using VBA is the only way to solve your task. I have modified the code to use the RGB colours. You can access RGB colours by right clicking a cell, then select Format Cells->Font->More Colors->Custom.
Sub ChangeIncellCharacterColour()
Dim rSelectedRange As Range
Dim vMyCharacter As Variant
Dim c As Integer
Dim rCell As Range
Dim iRed As Integer, iGreen As Integer, iBlue As Integer
On Error GoTo HandleErrors
vMyCharacter = Application.Range("rngMyCharacter")
iRed = Range("rngRed")
iGreen = Range("rngGreen")
iBlue = Range("rngBlue")
Set rSelectedRange = Selection
'Loop all cells in the selected
For Each rCell In rSelectedRange
'Loop characters in the current cell
For c = 1 To Len(rCell)
'Set colour of the character if it's value matches our parameter
If rCell.Characters(c, Len(vMyCharacter)).Text = vMyCharacter Then
rCell.Characters(c, Len(vMyCharacter)).Font.Color = RGB(iRed, iGreen, iBlue)
End If
Next c
Next rCell
HandleErrors:
End Sub
Please also see attached the modified example file
Hope this helps
Kind regards
Yury