ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   General Text Search and Highlight (https://www.excelbanter.com/excel-programming/284908-general-text-search-highlight.html)

Jeffro[_2_]

General Text Search and Highlight
 
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

[email protected]

General Text Search and Highlight
 

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
--------------------------------------------------------------------------------------------------------------
Be advised to back up your WorkBook before attempting to make changes.
--------------------------------------------------------------------------------------------------------------

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



Tom Ogilvy

General Text Search and Highlight
 
See the help example in the VBE for FindNext

--
Regards,
Tom Ogilvy

"Jeffro" wrote in message
om...
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





All times are GMT +1. The time now is 08:20 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com