View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Find and highlight results macro

Just to add --
Most of the code provided can be found in the vba help on the findnext
method. In both cases, since you are only marking the found cell and not
removing the searched for text, the terminating condition only needs to be:

Loop While c.Address < firstAddress

rather than

Loop While Not c Is Nothing And c.Address < firstAddress

c will never be nothing.


--
Regards,
Tom Ogilvy


"Toppers" wrote in message
...
Hi,

Sub FindAndColour()

Dim c as range
Dim Findstr As String

Findstr = InputBox("Enter search string") ' Enter your search string

With Worksheets(1).Range("a1:D500") ' Change to reflect your search

range
Set c = .Find(Findstr, LookIn:=xlValues,Lookat:=XlWhole)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.EntireRow.Interior.ColorIndex = 4 ' Set row to green
Set c = .FindNext(c) ' Look for next occurence of search

string
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With


HTH

"Mick" wrote:

Is it possible to program Excel's Find dialog so that it will search for

all
occurrences of a given string and highlight the rows containing the

search
string?

What I need is a macro (or something) that will prompt me for a string

to
look for, then go through every cell and highlight the rows that contain

the
string I specified.

Does anyone have a macro for this?

If not, can someone please help me create a macro that will do this?