coloring specific text within a cell

Tody03

New Member
Joined
Jun 21, 2014
Messages
48
In My spread sheet i have the words Brkfst & NRF in the same cell. I want to color the Brkfst in Green and the NRF in Red.
How can I do it in a macro?
Thanks
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Hi, so long as the cells contain text and not a formula you could try something like this. This is set to work on Sheet6, column H but you can adjust to suit

Code:
Sub ColorPart()
Dim StartC As Integer
Dim LenC As Integer
Dim lstRow As Integer
Dim i As Integer


With Sheet6
lstRow = .Range("H" & Rows.Count).End(xlUp).Row


For i = 1 To lstRow
        StartC = InStr(1, .Cells(i, 8).Value, "Brkfst")
        If StartC <> 0 Then
            LenC = 6
            .Cells(i, 8).Characters(Start:=StartC, Length:=LenC).Font.Color = vbGreen
        End If
        StartC = InStr(1, .Cells(i, 8).Value, "NRF")
        If StartC <> 0 Then
            LenC = 3
            .Cells(i, 8).Characters(Start:=StartC, Length:=LenC).Font.Color = vbRed
        End If
Next i
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,217,972
Messages
6,139,695
Members
450,226
Latest member
DrKraGeN

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top