General Text Search and Highlight

  • Thread starter Thread starter Jeffro
  • Start date Start date
J

Jeffro

Been trying to find a macro, example on how I might perform a find
that will highlight all occurences of a word that I want to search for
throughout a worksheet. Any suggestions would be much appreciated.

Thanks,

Jeffro
 
Sub FindMe()
' Highlights cells that contain "Hello"

Dim rngC As Range
Dim strToFind As String, FirstAddress As String

strToFind = "Hello"

With ActiveSheet.UsedRange
Set rngC = .Find(what:=strToFind, LookAt:=xlPart, _
LookIn:=xlFormulas)
If Not rngC Is Nothing Then
FirstAddress = rngC.Address
Do
rngC.Interior.Pattern = xlPatternGray50
Set rngC = .FindNext(rngC)
Loop While Not rngC Is Nothing And rngC.Address <> _
FirstAddress
End If
End With

End Sub

Tested using Excel 97SR2 on Windows 98SE,

HTH
Paul
 
Back
Top