A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.
Try the following
Sub Macro2()
Dim ws As Worksheet
Dim rngToFind As Range 'Individual cell to find
Dim rngFormat As Range 'Used to save the range of all cells that meet the Find
Dim strFirstAddr As String 'Address of first found cell in the range that meets the Find criteria
Set rngFormat = Nothing 'Just good programming to ensure that the variable does not already contain a range
Set ws = Worksheets("Sheet1") 'Edit "Sheet1" to your worksheet name
'*********************************************************************
'Between asterisk lines sets the required criteria for the FindFormat and ReplaceFormat
Application.FindFormat.Clear
Application.FindFormat.Interior.Color = 14277081
Application.ReplaceFormat.Interior.ColorIndex = -4142
Application.FindFormat.Locked = True
Application.FindFormat.FormulaHidden = False
'*********************************************************************
'Loop through the range and find all cells that meet the Find and FindFormat Criteria
With ws.Range("A1:AG7")
Set rngToFind = .Find(What:="*", _
SearchFormat:=True)
If Not rngToFind Is Nothing Then
strFirstAddr = rngToFind.Address
End If
Do
If rngFormat Is Nothing Then
Set rngFormat = rngToFind
Else
Set rngFormat = Union(rngFormat, rngToFind)
End If
Set rngToFind = .FindNext(rngToFind)
If rngToFind Is Nothing Then Exit Do
Loop While rngToFind.Address <> strFirstAddr
'Replace cells in the range that contain any value with the Replaceformat
'Note that following code is still within the With range.
If Not rngFormat Is Nothing Then
.Replace What:="*", _
Replacement:="", _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False, _
SearchFormat:=True, _
ReplaceFormat:=True
End If
End With
End Sub