Formatting Query in Excel

vksharma00001

Board Regular
Joined
Jun 9, 2014
Messages
116
Hi Experts
I have a query related to formatting.
I have a data where some names are given
1. Vijay Kumar Sharma
2. Vikas Gupta
3. Dinesh Sharma

My requirement is Where excel find the word “Sharma” , it will change the format of text “Sharma” only to red colour. Output should be like this. I want the solution only by Excel.
1. Vijay Kumar Sharma
2. Vikas Gupta
3. Dinesh Sharma
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Select all the cells with names in them, then run this macro.
Code:
Sub Sharma()
Dim c As Range, s As Long
Application.ScreenUpdating = False
For Each c In Selection
    s = InStr(c.Value, "Sharma")
    If s > 0 Then
        With c.Characters(s, Len("sharma"))
            .Font.Color = vbRed
        End With
    End If
Next c
Application.ScreenUpdating = True
End Sub
 
Upvote 0
.
.

Try something like this:

Code:
Sub FontColor()
    
    Dim trng As Range
    Dim cell As Range
    Dim strg As String
    Dim leng As Byte
    Dim strt As Byte
    
    If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
    
    strg = "Sharma"    'text for search
    leng = Len(strg)
    
    On Error Resume Next
    Set trng = ActiveSheet.Cells.SpecialCells( _
        xlCellTypeConstants, _
        xlTextValues)
    On Error GoTo 0
    
    If trng Is Nothing Then Exit Sub
    
    For Each cell In trng
        strt = InStr(LCase(cell.Value), LCase(strg))
        If strt <> 0 Then
            cell.Characters(Start:=strt, Length:=leng) _
                .Font.Color = RGB(255, 0, 0)
        End If
    Next cell

End Sub
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,240
Members
448,555
Latest member
RobertJones1986

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