excel macro

N

Nilesh Bhuvad

if in cell(a1).value = "1544*". and in cell(a2).value = "4144".
How to write syntax if cell value containing character "*", then only "*" will become red in colour and other character of the cell will remain as it is.
 
J

Joshua Fandango

Hi Nilesh,

Interesting question. Will every cell that contains the * be 5
characters in length?

JF
 
G

Gord Dibben

Sub Highlight_Word()
Dim rng As Range
Dim Cell As Range
Dim start_str As Integer
On Error GoTo endit
Mylen = Len("*")
Set rng = ActiveSheet.UsedRange
rng.Cells.Font.ColorIndex = 0
For Each Cell In rng
start_str = InStr(Cell.Value, "*")
If start_str Then
Cell.Characters(start_str, Mylen).Font.ColorIndex = 3
End If
Next Cell
endit:
End Sub

Will color only the first occurrence of * in a cell


Gord Dibben MS Excel MVP
 
Top