[Solved] Change letter colors ?

How to change the color of letters in a cell, mass change ???
Hello Craige Harper
Thanks for posting your query. You want to change the color of a particular text in a cell. We can easily do this by selecting the text and changing its color. Assuming you will do this a lot of time for various cell texts. In this case, you can use the Excel VBA code. I will show you both of these ideas.

Typical Method:
Select the desired cell >> mark the intended texts >> go to Home >> expand Font Color >> apply a color.
Select intended text in a cell and change color.png

Excel VBA:
First, choose a cell >> navigate to Developer >> click on Visual Basic.
Choose the cell and go to Developer followed by Visual Basic.png
Choose Insert followed by Module >> paste the following code and Run.
Code:
Sub ChangeColorOfText()
    
    Dim searchText As String
    Dim rng As Range
    Dim cell As Range
    Dim startPos As Long
    Dim lenSearchText As Integer

    searchText = InputBox("Enter the specific text you want to change the color of:", "Text Color Change")

    If searchText = "" Then
        Exit Sub
    End If

    lenSearchText = Len(searchText)

    For Each rng In Selection
        rng.Font.Color = vbBlack
        startPos = InStr(1, rng.Value, searchText, vbTextCompare)

        Do While startPos > 0
            rng.Characters(startPos, lenSearchText).Font.Color = RGB(255, 0, 0)
            startPos = InStr(startPos + 1, rng.Value, searchText, vbTextCompare)
        Loop
    Next rng

End Sub
Insert Intended code and Run.png
Consequently, the Text Color Change window will pop up. Input the intended text >> hit OK.
Insert intended text in Text Color Change window and hit OK.png
As a result, we will see an output like the below one.
Output of Running Excel VBA code to change color of a text.png

I have attached the solution Workbook to help you understand better. Don't hesitate to contact us again if you have any more questions.

Regards
Lutfor Rahman Shimanto
 

Attachments

Online statistics

Members online
0
Guests online
1,340
Total visitors
1,340

Forum statistics

Threads
456
Messages
2,020
Members
1,886
Latest member
taixiuonlinecab
Back
Top