A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
When you find or replace data, you can specify formatting. For example, let's say you want to find the word Test in column M, but only if the cell is bold.
Sub FindTest()
Dim rngFound As Range
' Specify the format to find
With Application.FindFormat
.Font.Bold = True
End With
Set rngFound = Range("M:M").Find(What:="Test", _
LookIn:=xlValues, LookAt:=xlPart, SearchFormat:=True)
If Not rngFound Is Nothing Then
MsgBox "Found in cell " & rngFound.Address, vbInformation
Else
MsgBox "Not found", vbInformation
End If
End Sub
Similarly, if you want to apply formatting while replacing, specify ReplaceFormat.
The following example will replace the bold word Test with non-bold, red Testing.
Sub ReplaceTest()
With Application.FindFormat
.Font.Bold = True
End With
With Application.ReplaceFormat
.Font.Bold = False
.Font.Color = vbRed
End With
Range("M:M").Replace What:="Test", Replacement:="Testing", _
LookAt:=xlPart, SearchFormat:=True, ReplaceFormat:=True
End Sub