Macro - Loop or Next

R

Rashid

I am a new to Excel VBA and trying write a macro for find a specific word in
a range. If the specific word is found change the colour.

My problem is how to get a loop going ?? here is my code PLEASE HELP

Sub colour()
Application.ScreenUpdating = False
Range("A:A").Select

Selection.find(What:="summary", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, _
MatchCase:=False).Activate
ActiveCell.Select
ActiveCell.Font.Bold = True
ActiveCell.Font.ColorIndex = 3

Next

End Sub
 
N

Norman Jones

Hi Rashid,

From VBA help:
'==============================
Find Method Example

This example finds all cells in the range A1:A500 on worksheet one that
contain the value 2, and then it makes those cells gray.

With Worksheets(1).Range("a1:a500")
Set c = .Find(2, lookin:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Interior.Pattern = xlPatternGray50
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
'==============================
 
G

Gerencsér Gábor

Sub MyMarker()
Dim os
Dim MyString As String
MyString = InputBox("Search for this: ", "MyMarker")
Cells.Find(What:=MyString, After:=ActiveCell, LookIn:=xlFormulas,
LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False) _
.Activate
Selection.Font.ColorIndex = 3
os = ActiveCell.Address
Cells.FindNext(After:=ActiveCell).Activate
Selection.Font.ColorIndex = 3

Do Until ActiveCell.Address = os
Cells.FindNext(After:=ActiveCell).Activate
Selection.Font.ColorIndex = 3
Loop
End Sub

Cheers, Gabor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top