VBA to Find and Change Format including partial text

tm11excel

New Member
Joined
Sep 22, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I use this code to find instances where text in cells is red and then highlight those cells.
Note that I don't want to change the red text, just want to highlight the cell.

Application.FindFormat.Font.Color = 255
Application.ReplaceFormat.Interior.Color = 65535
Range("A:N").Replace What:="", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByColumns, MatchCase:=False, SearchFormat:=True, _
ReplaceFormat:=True
Application.FindFormat.Clear
Application.ReplaceFormat.Clear

The problem is where random text within cells was selected and changed to red font. Is there a way that these cells can be highlighted as well?

Thank you in advance!
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Welcome to the forum,

Not sure how that can be edited to do what you need but the below may help:

VBA Code:
Sub test()
    Dim rCell As Range
    Dim x As Long
 
    For Each rCell In ActiveSheet.UsedRange
        For x = 1 To Len(rCell)
            If rCell.Characters(x, 1).Font.Color = vbRed Then
                rCell.Interior.Color = vbYellow
                Exit For
            End If
        Next x
    Next rCell
End Sub
 
Upvote 0
Similar to @Georgiboy, but limiting the range further to your A:N definition. The downside of this code is that it will be relatively slow if the number of cells is large.
VBA Code:
    Dim rng As Range
    Dim R As Range
    Dim I As Long

    With ActiveSheet
        Set rng = Application.Intersect(.UsedRange, .Range("A:N"))
    End With
    
    For Each R In rng
        For I = 1 To Len(R.Text)
            If R.Characters(I, 1).Font.Color = vbRed Then
                R.Interior.Color = vbYellow
                Exit For
            End If
        Next I
    Next R
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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